iamkun / iamkun/dayjs

"0000-00-00 00:00:00" gets changed to "1899-30-11 08:00:00" rather than producing an error

Open
#2,069 0 comments 2 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 the date `0000-00-00 00:00:00` is input, rather than a formatted version of that, or "Invalid Date", or null being returned, the date is changed silently to `1899-30-11 08:00:00` - not consistent with the +/- 100,000,000 days from Epoch time as outlined in ECMAScript docs

**Expected behavior**
The expectation is that it should return either `0000-00-00 00:00:00` or null in the Dayjs object (as mentioned in https://github.com/iamkun/dayjs/issues/70 - null is a valid date under the ECMAScript Docs, and is returned by many databases, so feels odd to fork from that...) and then the format function should return "Invalid Date"- because understandably, you can't format invalid dates with any consistency.

An error seems preferable, but [ECMAScript Docs ](https://262.ecma-international.org/5.1/#sec-15.9.1.15) recommend replacing all date zeros with 1's and times stay 0, so that would be consistent and expected behavior too:
"If the MM or DD fields are absent “01” is used as the value. If the HH, mm, or ss fields are absent “00” is used as the value and the value of an absent sss field is “000” "

**Information**
- Day.js Version 1.11.5
- OS: macOS 12.6
- Browser Vivaldi 5.4.2753.51
- Time zone: PDT GMT-07:00 (Pacific Daylight Time)

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with Day.js 1.11.5 using the input `0000-00-00 00:00:00` in the reported PDT environment, then trace the date parsing and formatting entry points. Add regression coverage for the invalid or normalized result and verify that formatting no longer silently produces `1899-30-11 08:00:00`.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.