dayjs
dayjs copied to clipboard
Using dayjs.tz.setDefault with endOf('day') makes the date tomorrow
Describe the bug
If I set the global timezone with dayjs.tz.setDefault()
and use dayjs.tz()
with endOf('day')
I get the next day.
- 2020-01-08T23:05:05-08:00 (date I used)
- 2020-01-09T23:59:59-08:00 (date I get)
- 2020-01-08T23:59:59-08:00 (date I should get)
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault("America/Los_Angeles");
dayjs.tz("2020-01-08T23:05:05-08:00").endOf("day").format(); // 2020-01-09T23:59:59-08:00 (wrong date)
Using dayjs().tz().endOf("day")
works correctly but not dayjs.tz().endOf("day")
:
// This works correctly:
dayjs("2020-01-08T23:05:05-08:00").tz("America/Los_Angeles").endOf("day").format(); // 2020-01-08T23:59:59-08:00
// This does not work correctly (same code above in the first example)
dayjs.tz.setDefault("America/Los_Angeles");
dayjs.tz("2020-01-08T23:05:05-08:00").endOf("day").format(); // 2020-01-09T23:59:59-08:00 (wrong date)
Expected behavior
I expect the end of day be the same of the date being passed in.
Also startOf("day")
causes the same issue so I don't think it's only related to endOf("day")
and startOf("day")
.
Information
- Day.js Version 1.10.3
- OS: macOS Catalina 10.15.7
- Browser Google Chrome Version 87.0.4280.88
- Time zone: GMT-06:00 DST (Central Daylight Time)