iamkun / iamkun/dayjs

.format('YYYY') returns less than 4 digits for years < 1000

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

Description

According to the [documentation](https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens), `YYYY` should return the 4-digit year. However, if the year is smaller than 1000 it returns a year with less than 4 digits.

For example, `dayjs('0202-01-01').format('YYYY-MM-DD')` returns `202-01-01`, which is to my understanding an invalid ISO date. It should return `0202-01-01` instead.

Contributor guide

Open the contributing guide

Research direction

Reproduce the reported dayjs('0202-01-01').format('YYYY-MM-DD') result, then locate the YYYY token formatting path in the Day.js codebase. Add a regression test covering years below 1000 and verify that the formatted result is 4 digits while the existing formatting behavior remains intact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.