Creating a UTC object from a dayjs object fails
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Do this:
`let plainDate = '2018-02-20T23:59:59.000Z';`
`let obj = dayjs(plainDate);`
`console.log(1, dayjs.utc(plainDate).toISOString());`
`console.log(1, dayjs.utc(obj).toISOString());`
`console.log(2, dayjs(plainDate).utc().toISOString());`
`console.log(2, dayjs(obj).utc().toISOString());`
The second console.log will print an incorrect date (today at 00:00:00) instead of the original date passed. Doing this however:
`console.log(1, dayjs.utc(obj.toDate()).toISOString());`
Seems to work just fine.
**Expected behavior**
Creating UTC Dayjs objects should work the same way as creating regular dayjs objects, which means passing a dayjs object as a parameter should work just fine. Instead, creating a dayjs object from a dayjs object works only if you do `dayjs()` but not `dayjs.utc()`.
**Information**
- Day.js Version 1.9.6
- OS: Windows 10
- Browser Edge 87
- Time zone: CET
Contributor guide
Research direction
Start by reproducing the issue with the dayjs.utc(obj) and dayjs(obj).utc() entry points shown in the report, comparing both results with the original ISO string. Trace how a Day.js object is handled by UTC creation, then verify that passing the object preserves the same instant and that the reported console outputs match the expected dates.
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
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100