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.

The problem with timezones

See original GitHub issue

The problem:

  1. A user selects a date with ember-power-calendar. Let’s say it was: Sat Oct 20 2018.
  2. The addon returns as a date field native JS Date object with the user’s browser timezone. In my case, it is: Sat Oct 20 2018 00:00:00 GMT+0100 (British Summer Time).
  3. Since Date object is nicely consumable by ember-data the developer might easily pass that value directly to some model property.
  4. 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.
  5. 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:open
  • Created 5 years ago
  • Reactions:8
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

fran-worleycommented, Oct 15, 2018

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.

jonnygreencommented, Sep 21, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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 Post

No results found

github_iconTop Related Hashnode Post

No results found