-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Describe the bug
Try this in GMT+0800 timezone:
dayjs('2024-10-20T01:00:00').utc().utcOffset(0, true).set('hour', 2);
// -> Sat, 19 Oct 2024 10:00:00 GMT
dayjs('2024-10-20T01:00:00').utc().utcOffset(0, true);
// -> Sun, 20 Oct 2024 01:00:00 GMT
dayjs('2024-10-20T01:00:00').utc().utcOffset(0, true).add(1, 'hour');
// -> Sun, 20 Oct 2024 02:00:00 GMT
// this also have wrong behavior
dayjs('2024-10-20T01:00:00').utcOffset(0, true).set('hour', 2);
// -> Sat, 19 Oct 2024 10:00:00 GMT
dayjs('2024-10-20T01:00:00').utc(true).utcOffset(0, true).add(1, 'hour');
// -> Sun, 20 Oct 2024 10:00:00 GMT
The aim is to turn to user's timezone and then change hour or date, the timezone may be 0 ~12.
Expected behavior
dayjs('2024-10-20T01:00:00').utc().utcOffset(0, true).set('hour', 2); should get Sun, 20 Oct 2024 02:00:00 GMT;
It seem because the utcOffset method doesn't change the $d.
Information
- Day.js Version: [ v1.11.10 ~ v1.11.13]
- OS: [MacOS]
- Browser [Node 18.19]
- Time zone: [ GMT+08:00 (Asia/Shanghai)]
Metadata
Metadata
Assignees
Labels
No labels