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
Converting a UTC time to a local time using timezone plugin seems to apply the difference in DST compare to the current time when converting back to JSON.
So if I have a time expressed in Europe/Stockholm DTS time, and my machine is on Stockholm standard time, when converting the time to JSON, an extra hour seems to be subtracted.
Example:
Today is 2022-02-24, I'm in Europe/Stockholm which is currently on standard time, no daylight savings, so UTC+01:00.
import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
dayjs.extend(utc);
dayjs.extend(timezone);
const winterUtc = dayjs.utc('2022-03-01T15:00:00Z');
console.log('Winter UTC JSON:', winterUtc.toJSON());
const winterLocal = winterUtc.tz('Europe/Stockholm'); // 15.00 UTC is 16:00+01:00 in March
console.log('Winter Europe/Stockholm format:', winterLocal.format());
// prints 2022-03-01T16:00:00+01:00 👍
console.log('Winter Europe/Stockholm UTC offset:', winterLocal.utcOffset());
// prints 60 👍
console.log('Winter Europe/Stockholm JSON:', winterLocal.toJSON());
// prints 2022-03-01T15:00:00.000Z 👍
const summerUtc = dayjs.utc('2022-06-01T15:00:00Z');
console.log('Summer UTC JSON:', summerUtc.toJSON());
const summerLocal = summerUtc.tz('Europe/Stockholm'); // 15:00 UTC is 17:00+02:00 in June
console.log('Summer Europe/Stockholm format:', summerLocal.format());
// prints 2022-06-01T17:00:00+02:00 👍
console.log('Summer Europe/Stockholm UTC offset:', summerLocal.utcOffset());
// prints 120 👍
console.log('Summer Europe/Stockholm JSON:', summerLocal.toJSON());
// prints 2022-06-01T14:00:00.000Z, should be 2022-06-01T15:00:00.000Z 👎
It's unclear to me if that always happens or if it's due to my local machine being on standard time while I'm computing a date in DST, and if the opposite problem would happen if my local machine is on DST while computing a "winter time" date.
Expected behavior
A time expressed in a time zone should be possible to convert to UTC / JSON by applying the UTC offset regardless of the local machine's own time zone.
Information
Day.js Version [e.g. v1.7.0]
OS: [e.g. MacOS 12]
Browser: N/A, Node 14
Time zone: Europe/Stockholm, UTC+01:00
The text was updated successfully, but these errors were encountered:
I confirmed that on 1.10.4, JSON representation is correct for a localized DST date, but instead the UTC offset is wrong, it's 60 instead of 120 even during the summer, meaning the formatted time is also +01:00 instead of +02:00.
On 1.10.5, the behaviour changed to correct format() but break toJSON() for localized DST dates.
// returns a date representing 2022-01-01T15:00:00Z, i.e. correct
dayjs.utc(`2022-01-01T15:00:00Z`).tz('Asia/Tokyo').utc();
// returns a date representing 2022-06-01T14:00:00Z, i.e. one hour off.
dayjs.utc(`2022-06-01T15:00:00Z`).tz('Asia/Tokyo').utc();
Note that Asia/Tokyo doesn't even have DST so why this extra hour is offset if converting a date in the summer I don't know, but I'm speculating it's because my local machine is in a time zone with DST during that period, in which case something is fishy since my local machine's time zone should not be involved at all here.
Describe the bug
Converting a UTC time to a local time using
timezone
plugin seems to apply the difference in DST compare to the current time when converting back to JSON.So if I have a time expressed in Europe/Stockholm DTS time, and my machine is on Stockholm standard time, when converting the time to JSON, an extra hour seems to be subtracted.
Example:
Today is 2022-02-24, I'm in Europe/Stockholm which is currently on standard time, no daylight savings, so UTC+01:00.
It's unclear to me if that always happens or if it's due to my local machine being on standard time while I'm computing a date in DST, and if the opposite problem would happen if my local machine is on DST while computing a "winter time" date.
Expected behavior
A time expressed in a time zone should be possible to convert to UTC / JSON by applying the UTC offset regardless of the local machine's own time zone.
Information
The text was updated successfully, but these errors were encountered: