[timezone] ISO string and date object are being parsed differently
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**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:
```js
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
```js
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`
Contributor guide
Research direction
Reproduce the examples using dayjs.tz, dayjs.utc, and the local parser under Europe/Stockholm, comparing the ISO string and Date object results. Trace the timezone parsing entry point and existing tests, then ensure both input types produce the same result as the expected Moment.js behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100