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] ISO string and date object are being parsed differently #1687

Open
dzonatan opened this issue Nov 9, 2021 · 0 comments · May be fixed by #1688
Open

[timezone] ISO string and date object are being parsed differently #1687

dzonatan opened this issue Nov 9, 2021 · 0 comments · May be fixed by #1688

Comments

@dzonatan
Copy link

dzonatan commented Nov 9, 2021

Describe the bug

There is a difference in result between what date type you provide when parsing under specific timezone.
This does not seem to be intentional. Let the code speak for itself:

const dateIso = '2019-07-03T00:00:00.000Z'; // doesn't really matter, could be any ISO8601 date
const dateObj = new Date(dateIso);

// local time (under GMT+3)
console.log(dayjs(dateIso).format());
// >> 2019-07-03T03:00:00+03:00 ✅
console.log(dayjs(dateObj).format());
// >> 2019-07-03T03:00:00+03:00 ✅

// utc
console.log(dayjs.utc(dateIso).format());
// >> 2019-07-03T00:00:00Z ✅
console.log(dayjs.utc(dateObj).format());
// >> 2019-07-03T00:00:00Z ✅

// timezone
console.log(dayjs.tz(dateIso, 'Europe/Stockholm').format());
// >> 2019-07-03T00:00:00+02:00 ❌ (-2 hours off), why?
console.log(dayjs.tz(dateObj, 'Europe/Stockholm').format());
// >> 2019-07-03T02:00:00+02:00 ✅

FIY: moment.js handles this uniformly

console.log(moment.tz(dateIso, 'Europe/Stockholm').format());
// >> 2019-07-03T02:00:00+02:00 ✅
console.log(moment.tz(dateObj, 'Europe/Stockholm').format());
// >> 2019-07-03T02:00:00+02:00 ✅

Information

  • Day.js v1.10.7
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