Skip to content

MongoDate conversion to DateTime fails in ambiguous edge case #273

@carlos-granados

Description

@carlos-granados

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions