DayJS parses wrong year value for the date "0001-01-01"
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:16 (5 by maintainers)
Top Results From Across the Web
dayjs returns wrong date with format - javascript - Stack Overflow
Try date = '1989-08-12' . What will be the result? · Your problem is your timezone .format format with your timezone. · 1....
Read more >Validation
Returns a boolean indicating whether the Dayjs 's date is valid. Non-strict check. Only checks if the value could be parsed to a...
Read more >Parse, Validate, Manipulate, and Display Dates and Times in ...
Parsing a date and time string into a Day.js object is easy and supports strings, numbers, native JavaScript Date objects as well as...
Read more >Connect CDC v5.8 System Reference Guide
The following expression gets a PARSE ERROR because of an improper use of a ... does: Convert DB2 dates with the value of...
Read more >News in the BRFplus Formula - SAP Blogs
A new formula parser has been written to better analyze the ... DT_IS_NULL, Returns TRUE if a Timepoint is NULL (date part is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@iamkun yo, just created a PR to fix this issue in which I refactored a bit the parseDate method using the method
setFullYearinspired by @naulacambraall tests has passed, could you plz review this PR? we really need this fix for our project, thx in advance.
So, we just can’t use this with a regular date input without writing a custom guard?
Seems pretty annoying considering the whole point of a date lib is to prevent having to parse and manipulate dates manually. Even more so when this is a problem for anyone who parses a date input’s value.