The problem with timezones
See original GitHub issueThe problem:
- A user selects a date with
ember-power-calendar
. Let’s say it was:Sat Oct 20 2018
. - The addon returns as a
date
field native JSDate
object with the user’s browser timezone. In my case, it is:Sat Oct 20 2018 00:00:00 GMT+0100 (British Summer Time)
. - Since Date object is nicely consumable by ember-data the developer might easily pass that value directly to some model property.
- Once ember-data tries to save that property (typically through json-api serializer), here’s what gets passed to the server:
2018-10-19T23:00:00.000Z
. - Then if the server stores only
DATE
, without the time part it might happen that the wrong date gets saved. That is actually how I bumped into this bug.
See the one hour difference that leads to a different date. That is because there is different timezone.
I kidna do understand that the information is still there and I can recalculate the “correct selected date” using the information about user’s timezone. But I feel like the consumer of this addon should not care about this. If the addon always returns date in UTC, then there should be no problem. Something like:
new Date(Date.UTC(2018, 10, 20));
Tue Nov 20 2018 00:00:00 GMT+0000 (Greenwich Mean Time)
I tried to isolate a minimum reproducible code here.
Thanks for consideration.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Falsehoods programmers believe about time zones - Zain Rizvi
Misconception #3: There are more countries in the world than time zones. How could this one possibly be wrong? Well... Many countries want...
Read more >The case against time zones: They're impractical & outdated
The problem, however, is that it is difficult for people to collaborate across time zone boundaries. Consequently, the real world time zones ......
Read more >The Problem with Time & Timezones - Computerphile - Reddit
The problem was to calculate the number of seconds from an arbitrary date based on the current time zone, but a practical example...
Read more >The Timezone Struggle - Medium
I've stored all the dates/times a student has tested themselves in a database, now all I need to do is get today's date,...
Read more >What's wrong with your time zone? - Remote
TL;DR · Just use UTC as your main time zone to schedule calls. · Time zones are the commute of remote work: an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For me it would be useful is if you could configure the datepicker for moment to be in utc mode (and for dates, it might be sensible to turn this on by default).
It’s such a pain that for half the year all my dates are out by 1 day unless I override the getting/ setting of moment.
On reflection, my comment above is not a good solution as timezones that are behind UTC would end up with a date object that if interpreted as local time, would be a day early. So big backwards compatibility issues. Whoops 🤦.
It needs something though - I think @fran-worley’s approach of being able to configure
PowerCalendar
in UTC mode is a good one. In the meantime, we’re implementing a wrapper that massages the date object to produce the date we expect in UTC.