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

Timezone conversion to same timezone keeping time returns wrong valueOf #2763

Open
fabio-moyano-s1 opened this issue Nov 1, 2024 · 0 comments

Comments

@fabio-moyano-s1
Copy link

fabio-moyano-s1 commented Nov 1, 2024

Describe the bug
When you convert a date to the same timezone and with the keepLocalTime set as true the valueOf function returns the wrong milis value.

See this code snippet:

import dayjs from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';

dayjs.extend(timezone);
dayjs.extend(utc);

// Update: Apparently it only happens when the timezone is UTC
const timezoneToUse = 'UTC'

// Set default timezone
dayjs.tz.setDefault(timezoneToUse);

const date1 = dayjs.tz('2021-08-09T12:45:00Z');
console.log(date1.format()); // 2021-08-09T12:45:00Z
console.log(date1.valueOf()); // 1628513100000

const date2 = dayjs.tz('2021-08-09T12:45:00Z').tz(timezoneToUse);
console.log(date2.format()); //  2021-08-09T12:45:00Z
console.log(date2.valueOf()); // 1628513100000

const date3 = dayjs.tz('2021-08-09T12:45:00Z').tz(timezoneToUse, true);
console.log(date3.format()); // 2021-08-09T12:45:00Z
console.log(date3.valueOf()); // 1628520300000 -> why?

Expected behavior
valueOf should return the same value regardless if you set keepLocalTime on or off if you are parsing from the same timezone.

Information

  • Day.js Version v1.11.13
  • OS: MacOS Sonoma 14.7
  • Browser Chrome v129.0.6668.91
  • Time zone: Europe/Prague
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

1 participant