iamkun / iamkun/dayjs

DayJS parses wrong year value for the date "0001-01-01"

Open
#1,237 18 comments 9 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 trying to parse the dates "0000-01-01" and "0001-01-01" DayJS returns the years 1900 and 1901 respectively:
```
const dayjs = require('dayjs')
console.log(dayjs("0001-01-01", "YYYY-MM-DD"))
```
Output:
```
d {
'$L': 'en',
'$d': 1901-01-01T03:06:28.000Z,
'$x': {},
'$y': 1901,
'$M': 0,
'$D': 1,
'$W': 2,
'$H': 0,
'$m': 0,
'$s': 0,
'$ms': 0
}
```

**Expected behavior**
The expected behavior is that the returned object has the correct year. Setting the year manually we can see the correct behavior working:
```
const dayjs = require('dayjs')
console.log(dayjs("2020-01-01", "YYYY-MM-DD").year(1))
```
Output:
```
d {
'$L': 'en',
'$d': 0001-01-01T03:06:28.000Z,
'$x': {},
'$y': 1,
'$M': 0,
'$D': 1,
'$W': 1,
'$H': 0,
'$m': 0,
'$s': 0,
'$ms': 0
}
```

**Information**
- Day.js Version v1.9.6
- OS: Windows
- Browser: N/A (Node.js v12.18.3)
- Time zone: GMT-03:00

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.