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
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.
MongoDate conversion to DateTime produces the wrong result during very specific cases due to DST time changes. For example, see this case:
1603584000
which corresponds to2020-10-25T00:00:00Z
Europe\Madrid
toDateTime()
function does the following procedures:Europe\Madrid
timezone2020-10-25T02:00:00+02:00
(at this point in time the offset forEurope\Madrid
is +02:00)2020-10-25T00:00:00Z
or2020-10-25T01:00:00Z
.1603587600
which does not match our initial timestampThis 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