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
I'm creating a new dayjs object using an integer representing the millisecond time format for a moment in time. Outputting the object, the resulting date is correct and it has no time zone, but based on output it is in UTC as expected (human readable date ends in Z). If I then use the time zone plugin and adjust the time to UTC, the time is shifted as if the original time was in the local time of the machine running the code and not in UTC.
Expected behavior
Based on the string output of the original time, I'm expecting when assigning the UTC time zone to a dayjs object, the point in time is not shifted, but the presentation of the date might change to reflect the time zone.
The way Moment.js behaves in this case is, when creating the Moment object from the integer, the integer is interpreted as being in UTC, but the object is assigned the local time zone. When subsequently assigning the UTC zone to the Moment object, the moment in time remains constant, but the representation is shifted to UTC.
Example:
const d = dayjs(1434844800000);
const m = moment(1434844800000);
// d is now 2015-06-21T00:00:00.000Z with no zone in the dayjs object
// m is now 2015-06-21T03:00:00+03:00
// Note these dates are equal in terms of the moment in time
const zd = d.tz('UTC');
const zm = m.tz('UTC');
// zd is now 2015-06-20T21:00:00.000Z
// zm is now 2015-06-21T00:00:00Z
// Moment date is unchanged as a point in time, Dayjs time is shifted 3 hours
The logic I have that I'm porting has a persisted timestamp in UTC and code needs to know what time it was in a random time zone at that moment in time.
Information
Day.js Version 1.10.7
OS: Mac OS X 12.2
Node.js 16.13.2
Time zone: GMT+3
The text was updated successfully, but these errors were encountered:
Describe the bug
I'm creating a new dayjs object using an integer representing the millisecond time format for a moment in time. Outputting the object, the resulting date is correct and it has no time zone, but based on output it is in UTC as expected (human readable date ends in Z). If I then use the time zone plugin and adjust the time to UTC, the time is shifted as if the original time was in the local time of the machine running the code and not in UTC.
Expected behavior
Based on the string output of the original time, I'm expecting when assigning the UTC time zone to a dayjs object, the point in time is not shifted, but the presentation of the date might change to reflect the time zone.
The way Moment.js behaves in this case is, when creating the Moment object from the integer, the integer is interpreted as being in UTC, but the object is assigned the local time zone. When subsequently assigning the UTC zone to the Moment object, the moment in time remains constant, but the representation is shifted to UTC.
Example:
const d = dayjs(1434844800000);
const m = moment(1434844800000);
// d is now 2015-06-21T00:00:00.000Z with no zone in the dayjs object
// m is now 2015-06-21T03:00:00+03:00
// Note these dates are equal in terms of the moment in time
const zd = d.tz('UTC');
const zm = m.tz('UTC');
// zd is now 2015-06-20T21:00:00.000Z
// zm is now 2015-06-21T00:00:00Z
// Moment date is unchanged as a point in time, Dayjs time is shifted 3 hours
The logic I have that I'm porting has a persisted timestamp in UTC and code needs to know what time it was in a random time zone at that moment in time.
Information
The text was updated successfully, but these errors were encountered: