dayjs.utc returns current date when initialized with other Dayjs object
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
According to the UTC plugin [docs](https://day.js.org/docs/en/plugin/utc), `dayjs.utc` supports passing a `Dayjs` object as a parameter. This is also the way it's declared in the TS interfaces.
However, when passing a valid object, it initializes with the current date.
For example:
```
> const a = new Date("2022-05-31T21:00:00.000Z")
> const b = dayjs.utc(a);
> b.toString()
'Tue, 31 May 2022 21:00:00 GMT' // Same date as `a`, this is good
> const c = dayjs.utc(b);
> c.toString()
'Mon, 20 Jun 2022 00:00:00 GMT' // Back to current date. Not good
```
**Expected behavior**
It should return an object with the same date as the one passed to it.
**Information**
- Day.js Version: 1.11.2
- OS: MacOS Monterey 12.0.1
- Browser: NodeJS v14.19.1
- Time zone: GMT+3
Contributor guide
Research direction
Start by reproducing the issue through the dayjs.utc entry point with a Dayjs object, comparing it with the Date-object case described above. Locate the UTC plugin implementation and its existing tests, then add regression coverage showing that the returned object preserves the passed date.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100