question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timezone problems. Moves everything over a day

See original GitHub issue

Do you want to request a feature or report a bug?

screenshot 13 screenshot 14

Code for screenshot(13) //moment.tz.setDefault("America/Vancouver"); console.log(moment().format()); BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment));

Code for screenshot(14) moment.tz.setDefault("America/Vancouver"); console.log(moment().format()); BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment));

You can see that the current date in the calendar moves over to the 16th when it is in fact the 17th in both timezones. You can see that I am console logging the moment date out. Does anyone have any ideas on how to fix this?

What’s the current behavior?

You can see the error clearly in this sandbox: https://codesandbox.io/s/m34q6xw6lx

It shifts all of the days over by one. Saying the current date is one less than the real current date. Line 7 in the sandbox makes this occur, for some reason setting the moment timezone shifts all the days over by 1.

What’s the expected behavior?

The expected behavior would be to display the correct dates, instead of moving everything over a day.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:11

github_iconTop GitHub Comments

8reactions
goktugercecommented, Aug 18, 2020

I found a simple workaround for this, but it only works for display purposes. We are not doing any actions from the calendar apart from showing the events.

// Find the difference of hours between your local timezone and the requested timezone.
const gymOffset = moment.tz(gym.timezone).utcOffset();
const localOffset = moment().utcOffset();
const offsetHours = (gymOffset - localOffset) / 60;

// Change props startAccessor and endAccessor accordingly
<BigCalendar
   ...
   startAccessor={(event) => moment(event.from).clone().add(offsetHours, 'hours').toDate()}
   endAccessor={(event) => moment(event.to).clone().add(offsetHours, 'hours').toDate()}
/>

No need to do anything specific for the localizer, just use your local one without setting the default timezone for moment.

7reactions
thienlhhcommented, Apr 18, 2018

I have the same problem when setting the timezone that behind the local timezone

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with Timezones and All Day Events -
The problem is that everything comes in as UTC which confuses people. There is an option to force a timezone which works except...
Read more >
How to deal with dates and times without any timezone ...
Dates, times and timezones are troublesome things. Daylight saving, or “summer time” as it's also commonly known, makes matters even worse, ...
Read more >
The Problem with Time & Timezones - Computerphile - YouTube
A web app that works out how many seconds ago something happened. How hard can coding that be? Tom Scott explains how time...
Read more >
How to Handle Timezones and Synchronize Your Software ...
Rule #1 : Timestamps are only for saving, not for displaying. It's considered on UTC because it doesn't include any offset or time...
Read more >
How to fix time wrong in Google Calendar - OrganicWeb
The reason that this problem occurs is that your calendar timezone setting may be incorrect. Follow the instructions below to fix this issue:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found