Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utcOffset(0, true) with set('hour', n) bug, get wrong time. #2754

Open
lanistor opened this issue Oct 21, 2024 · 1 comment
Open

utcOffset(0, true) with set('hour', n) bug, get wrong time. #2754

lanistor opened this issue Oct 21, 2024 · 1 comment

Comments

@lanistor
Copy link

lanistor commented Oct 21, 2024

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
截屏2024-10-22 00 45 56

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)]
@lanistor lanistor changed the title utcOffset with set('hour', n) bug, get wrong time. utcOffset(0, true) with set('hour', n) bug, get wrong time. Oct 21, 2024
@josephmathew900
Copy link

josephmathew900 commented Nov 22, 2024

https://joseph-mathew.neetorecord.com/watch/03fcfa68-ba46-4aa7-8fc8-aabb8eace0ee

@iamkun Could you please check this issue? The UTC logic for the timezone plugin is added in PR #2693.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants