Skip to content

fix: handle Dayjs object input in dayjs.utc()#3036

Closed
Bahtya wants to merge 1 commit intoiamkun:devfrom
Bahtya:fix/utc-dayjs-object-input
Closed

fix: handle Dayjs object input in dayjs.utc()#3036
Bahtya wants to merge 1 commit intoiamkun:devfrom
Bahtya:fix/utc-dayjs-object-input

Conversation

@Bahtya
Copy link
Copy Markdown

@Bahtya Bahtya commented Apr 4, 2026

Problem

When passing a Dayjs object to dayjs.utc(), the result is incorrect — it returns today's date instead of the passed date.

const d = dayjs(2018-09-06)
dayjs.utc(d).format() // expected: 2018-09-06T00:00:00Z, actual: wrong date

This happens because dayjs.utc() passes the raw Dayjs object directly to the config, which goes through parseDate()new Date(date), producing incorrect results.

Solution

Add an isDayjs check at the top of dayjs.utc() to convert to a native Date first:

dayjs.utc = function (date) {
    if (dayjs.isDayjs(date)) date = date.toDate()
    ...
}

This mirrors how the core dayjs() function already handles Dayjs input.

Fixes #1241

When passing a Dayjs object to dayjs.utc(), the result was incorrect
because the raw Dayjs object went through parseDate() which called
new Date(date) producing wrong results.

Add isDayjs check to convert to native Date first.

Fixes #1241
@Bahtya Bahtya closed this by deleting the head repository Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating a UTC object from a dayjs object fails

1 participant