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

dayjs.tz returns different values depending on the type of input #2680

Open
20manas opened this issue Jun 17, 2024 · 0 comments · May be fixed by #2681
Open

dayjs.tz returns different values depending on the type of input #2680

20manas opened this issue Jun 17, 2024 · 0 comments · May be fixed by #2681

Comments

@20manas
Copy link

20manas commented Jun 17, 2024

Describe the bug
dayjs.tz(instance, timezone) returns different values depending on the type of input. If the instance is of type string, then the value returned is correct and as per the documentation: it sets the time in the specified timezone. But if it is anything else, it doesn't work properly: it sets the time in the local timezone, then updates the timezone to the specified timezone.

For example, if this is the input:

  // local timezone: UTC + 5:30

  const tz = 'Asia/Tokyo'; // UTC + 9
  const date = new Date(2023, 9, 8, 0, 0, 0, 0);

  const a = dayjs.tz('2023-10-08', tz);
  const b = dayjs.tz(date, tz);
  const c = dayjs.tz(date.valueOf(), tz);
  const d = dayjs.tz({year: 2023, month: 9, day: 8}, tz);

  console.info('test a', a.toISOString(), a.format());
  console.info('test b', b.toISOString(), b.format());
  console.info('test c', c.toISOString(), c.format());
  console.info('test d', d.toISOString(), d.format());

then this is the output:

test a 2023-10-07T15:00:00.000Z 2023-10-08T00:00:00+09:00
test b 2023-10-07T18:30:00.000Z 2023-10-08T03:30:00+09:00
test c 2023-10-07T18:30:00.000Z 2023-10-08T03:30:00+09:00
test d 2023-10-07T18:30:00.000Z 2023-10-08T03:30:00+09:00

Expected behavior
The output should be the same for all types of instances.

Information

  • Day.js Version: v1.11.11
  • OS: Linux
  • Browser: Firefox 126.0.1
  • Time zone: UTC + 5:30
@20manas 20manas linked a pull request Jun 17, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant