iamkun / iamkun/dayjs

Passing Day.js instance to Moment returns current date instead of original value

Open
#3,025 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When a Day.js instance is passed directly to Moment (`moment(dayjsValue)`), the resulting Moment date becomes the current date instead of the Day.js date for some inputs.

In my case, this caused a CSV export range bug: selecting `2026-03-01` to `2026-03-19` ended up sending `from` as `2026-03-19` (today), so only today's records were exported.

**Expected behavior**
`moment(dayjs('2026-03-01'))` should represent `2026-03-01`, not the current date.

**Actual behavior**
`moment(dayjs('2026-03-01')).format()` returns `2026-03-19...` (current day in my environment).

**Minimal reproduction**
```js
const moment = require('moment')
const dayjs = require('dayjs')

const d = dayjs('2026-03-01')

console.log('dayjs:', d.format()) // 2026-03-01T00:00:00+09:00
console.log('moment(dayjs):', moment(d).format()) // 2026-03-19T00:00:00+09:00 (unexpected)
console.log('moment(dayjs.toDate()):', moment(d.toDate()).format()) // 2026-03-01T00:00:00+09:00 (expected)
```
Day.js Version: 1.11.19
OS: Linux
Browser: N/A (Node.js reproduction)
Node.js: v24.0.0
Moment Version: 2.30.1
Time zone: Asia/Tokyo (GMT+09:00)

Contributor guide

Open the contributing guide

Research direction

Start with the Node.js minimal reproduction in the issue and compare moment(dayjsValue) with moment(dayjsValue.toDate()). Trace how the Day.js instance is passed into Moment for the affected inputs. Done means the direct conversion preserves the original date and a regression test covers the reported case.

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
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.