Unexpected parsing results when using timezone - migrating from moment.js to dayjs.js
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
I am in the process of migrating from moment.js to dayjs.js. I am getting unexpected results in a particular use case.
My device is currently using 'America/New_York' timezone and it is ~ 10/22/2024 @ 1:00AM. Meaning it is still the 21st in Los Angeles (3 hours behind me).
moment.js :
```
dateTZ = 'America/Los_Angeles';
date = moment().tz(dateTZ).startOf('day').format('MMM Do, YYYY [@] h:mm a z');
console.log(date); // returns 'Oct 21st, 2024 @ 12:00 am PDT' - correct
```
dayjs.js :
```
dateTZ = 'America/Los_Angeles';
date = dayjs().tz(dateTZ).startOf('day').format('MMM Do, YYYY [@] h:mm a z');
console.log(date); // returns 'Oct 21st, 2024 @ 6:00 am PDT' - wrong
```
Is there a different way to go about getting the result I am looking for with dayjs or is this just not possible with dayjs?
Contributor guide
Research direction
No source file or test is named. Start by reproducing the America/New_York to America/Los_Angeles example with the timezone-related Day.js plugins, then trace the handling of tz() followed by startOf('day'). Done means the behavior is explained and, if confirmed as a bug, covered by a regression test expecting midnight on October 21, 2024.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100