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
Describe the bug
Converting local date/time to UTC by calling utc() function sometimes provides incorrect results. This seems to be happening when the conversion is taking place during DST observation and the provided local date/time is a non-DST one (or vice versa).
For example, converting 2022-11-01T13:30:00+02:00 at the time of writing this issue results in 2022-11-01T12:30:00+00:00 where time is not being adjusted by a correct offset. Minimal reproducible example:
importdayjsfrom'dayjs';importutcfrom'dayjs/plugin/utc';importtimezonefrom'dayjs/plugin/timezone';importlocalizedFormatfrom'dayjs/plugin/localizedFormat';dayjs.extend(utc);dayjs.extend(timezone);dayjs.extend(localizedFormat);// Current time zone (summer time) and current local time for reference:consttz=dayjs.tz.guess();// Europe/Kievdayjs();// 2022-04-21T16:21:45+03:00// UTC date/time converted to local:constdateTimeDST=dayjs('2022-04-01T11:30:00Z').tz(tz);// 2022-04-01T14:30:00+03:00constdateTime=dayjs('2022-11-01T11:30:00Z').tz(tz);// 2022-11-01T13:30:00+02:00// Local date/time converted to UTC:dateTimeDST.utc();// 2022-04-01T11:30:00+00:00dateTime.utc();// 2022-11-01T12:30:00+00:00 (time is shifted by only 1 hour)
Similar thing happens when trying to convert a DST date/time when the DST observation has ended:
import{useFakeTimers}from'sinon';useFakeTimers(newDate('2022-11-01T11:30:00Z').getTime());consttz=dayjs.tz.guess();constdateTimeDST=dayjs('2022-04-01T11:30:00Z').tz(tz);// 2022-04-01T14:30:00+03:00dateTimeDST.utc();// 2022-04-01T10:30:00+00:00 (time is shifted by 4 hours)
Expected behavior
Since UTC doesn't observe DST, I expect utc() to adjust hours by the same amount as it's shown in format(). In this case, 2022-11-01T13:30:00+02:00 should be converted to 2022-11-01T11:30:00+00:00 (minus 2 hours) during DST observation and 2022-04-01T14:30:00+03:00 should be converted to 2022-11-01T11:30:00+00:00 (minus 3 hours) when the DST observation ends.
I can work around this issue by adjusting the minutes manually:
Describe the bug
Converting local date/time to UTC by calling
utc()
function sometimes provides incorrect results. This seems to be happening when the conversion is taking place during DST observation and the provided local date/time is a non-DST one (or vice versa).For example, converting
2022-11-01T13:30:00+02:00
at the time of writing this issue results in2022-11-01T12:30:00+00:00
where time is not being adjusted by a correct offset. Minimal reproducible example:Similar thing happens when trying to convert a DST date/time when the DST observation has ended:
Expected behavior
Since UTC doesn't observe DST, I expect
utc()
to adjust hours by the same amount as it's shown informat()
. In this case,2022-11-01T13:30:00+02:00
should be converted to2022-11-01T11:30:00+00:00
(minus 2 hours) during DST observation and2022-04-01T14:30:00+03:00
should be converted to2022-11-01T11:30:00+00:00
(minus 3 hours) when the DST observation ends.I can work around this issue by adjusting the minutes manually:
Information
The text was updated successfully, but these errors were encountered: