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
{{ message }}
Repository navigation
parseAbsolute and parseZonedDateTime apply minutes of negative UTC offsets in the wrong direction #10809
parseAbsolute returns the wrong instant for any negative UTC offset that has a minutes component, such as -03:30 (Newfoundland standard time) or -09:30 (Marquesas). parseAbsolute and parseZonedDateTime also drop the sign of offsets whose hour part is zero, such as -00:30 or the historical -00:44:30 used by Africa/Monrovia.
Expected Behavior
parseAbsolute('2021-11-07T07:45:00-03:30', 'UTC') returns 2021-11-07T11:15:00+00:00[UTC], the same instant as new Date('2021-11-07T07:45:00-03:30').
parseZonedDateTime(date.toString()) round trips a ZonedDateTime whose offset is -00:44:30.
Current Behavior
import{parseAbsolute,parseZonedDateTime,ZonedDateTime}from'@internationalized/date';parseAbsolute('2021-11-07T07:45:00-03:30','UTC').toString();// '2021-11-07T10:15:00+00:00[UTC]' (one hour early; Date gives 11:15Z)parseAbsolute('2021-11-07T07:45:00-00:30','UTC').toString();// '2021-11-07T07:15:00+00:00[UTC]' (offset treated as +00:30; Date gives 08:15Z)letdate=newZonedDateTime(1960,1,1,'Africa/Monrovia',-2670000,0,0,0);date.toString();// '1960-01-01T00:00:00-00:44:30[Africa/Monrovia]'parseZonedDateTime(date.toString());// Error: Offset +00:00 is invalid for 1960-01-01T00:00:00 in Africa/Monrovia
Root cause
In packages/@internationalized/date/src/string.ts:
parseAbsolute computes the offset as hours * 3600000 + minutes * 60000. For -03:30 the hours are -3 and the minutes are added as positive, giving -02:30.
parseZonedDateTime multiplies by Math.sign(hourOffset), which handles -03:30 but is 0 (or -0) when the hour part is -00, so the minutes and seconds lose their sign.
Possible Solution
Take the sign from the first character of the hour string and apply it to the whole offset, in one helper used by both functions.
Activity