Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDate conversion to DateTime fails in ambiguous edge case #273

Closed
carlos-granados opened this issue Oct 28, 2020 · 1 comment
Closed
Labels
Milestone

Comments

@carlos-granados
Copy link

MongoDate conversion to DateTime produces the wrong result during very specific cases due to DST time changes. For example, see this case:

  • We have a MongoDate with timestamp 1603584000 which corresponds to 2020-10-25T00:00:00Z
  • Suppose that our local timezone is Europe\Madrid
  • The code for the toDateTime() function does the following procedures:
  • Create a DateTime, this will be created in the Europe\Madrid timezone
  • Set the timestamp, this will generate a DateTime with the data 2020-10-25T02:00:00+02:00 (at this point in time the offset for Europe\Madrid is +02:00)
  • Set the timezone for this object to UTC. However there is a problem, this is exactly the time when the clocks change due to DST. And there is an ambiguity as this time can be expressed as 2020-10-25T00:00:00Z or 2020-10-25T01:00:00Z.
  • Setting the timezone to UTC produces the second result which does not match what we expected. The timestamp for this DateTime is 1603587600 which does not match our initial timestamp

This would be fixed if we inverted the process so that we first set the timezone of the newly created object to UTC and then set the timestamp

@alcaeus
Copy link
Owner

alcaeus commented Oct 28, 2020

Thanks for the report. Fixing in #274, which also uses the exact same timestamp that you used in your tests. I'll release a fix once the build is stable.

@alcaeus alcaeus closed this as completed Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants