You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I understand from Wikipedia, offsets in ISO timestamps represent the offset from UTC of a ISO 8601 string in the local (offset) time zone. That is, the time given before the Z or ±hh:mm is the local time, and the offset gives the difference between the local time and UTC.
Assuming this is correct, then this means that the following should all be equivalent:
All this given, I understand that the relationship between the local time local_time, UTC time utc_time and local time zone offset offset should be utc_time = local_time - offset. (Note the subtraction of the offset, not addition!)
Perhaps you might be able to explain whether this is correct? Someotherpeople agree. Likewise the datetime standard library in Python agrees (note tm_hour=1 on the last line):
As far as I can see, when localtime is true, then the offset should be ignored entirely, and this should give back NanoDate(2022, 06, 18, 12, 15, 30, 123, 456, 789) (hour is 12).
When localtime is false, on the other hand, it should give NanoDate(2022, 06, 18, 16, 15, 30, 123, 456, 789) (hour is 12 – (–4) = 16).
As far as I can see, to fix this, the behaviour of localtime in the NanoDate constructor should be switched, and the offset should be subtracted, not added, in getting the UTC time.
Am I right, or have I got horribly confused?
The text was updated successfully, but these errors were encountered:
So I think the issue is just with parsing dates with offsets.
(Just to note my preference—I think that parsing dates with offsets should give you back UTC by default, with the option to ignore the offset and return the local time. At present, it's the other way round (even if it appears to have a bug!), so it would be a breaking change.)
anowacki
changed the title
Local time and offsets the wrong way round?
Local time and offsets the wrong way round when parsing/construction from string
Aug 20, 2024
As far as I understand from Wikipedia, offsets in ISO timestamps represent the offset from UTC of a ISO 8601 string in the local (offset) time zone. That is, the time given before the
Z
or±hh:mm
is the local time, and the offset gives the difference between the local time and UTC.Assuming this is correct, then this means that the following should all be equivalent:
2000-01-01T06:00:00Z
2000-01-01T06:00:00+00:00
2000-01-01T00:00:00-06:00
2000-01-01T12:00:00+06:00
All this given, I understand that the relationship between the local time
local_time
, UTC timeutc_time
and local time zone offsetoffset
should beutc_time = local_time - offset
. (Note the subtraction of the offset, not addition!)Perhaps you might be able to explain whether this is correct? Some other people agree. Likewise the
datetime
standard library in Python agrees (notetm_hour=1
on the last line):If the above is all correct, then I think that NanoDates has offsets implemented the wrong way round. One of the tests:
As far as I can see, when
localtime
istrue
, then the offset should be ignored entirely, and this should give backNanoDate(2022, 06, 18, 12, 15, 30, 123, 456, 789)
(hour is 12).When
localtime
isfalse
, on the other hand, it should giveNanoDate(2022, 06, 18, 16, 15, 30, 123, 456, 789)
(hour is 12 – (–4) = 16).As far as I can see, to fix this, the behaviour of
localtime
in theNanoDate
constructor should be switched, and the offset should be subtracted, not added, in getting the UTC time.Am I right, or have I got horribly confused?
The text was updated successfully, but these errors were encountered: