dayjs
dayjs copied to clipboard
fix: .format('YYYY') returns less than 4 digits for years < 1000
close #1745
Codecov Report
Merging #1953 (4b14ff6) into dev (cbe91fd) will not change coverage. The diff coverage is
n/a.
:exclamation: Current head 4b14ff6 differs from pull request most recent head fb0db64. Consider uploading reports for the commit fb0db64 to get more accurate results
@@ Coverage Diff @@
## dev #1953 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 183 183
Lines 2096 2096
Branches 550 550
=========================================
Hits 2096 2096
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/index.js | 100.00% <ø> (ø) |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
I had the same problem and came up with the same solution.
The documentation clearly says: https://github.com/dayjs/dayjs-website/blob/8336b896f5584f161ac99ed502ede6ad21bc74f6/docs/display/format.md?plain=1#L22-L25
| Format | Output | Description |
|---|---|---|
YY |
18 | Two-digit year |
YYYY |
2018 | Four-digit year |
So right now, the code does not conform to the documentation. But this PR fixes that.
As an improvement, I would just add a Y format that keeps the original value of this.$y, just in case,
and reuse Utils.s(this.$y, 2, '0') in YY for consistency.
Y: this.$y,
YY: Utils.s(this.$y, 2, '0'),
YYYY: Utils.s(this.$y, 4, '0'),
@iamkun can you please review this
@iamkun Can you please review this?