Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'YYYY' results in missing leading zeroes when year <1000 #2230

Closed
Sharparam opened this issue Feb 7, 2023 · 1 comment · Fixed by #2231
Closed

'YYYY' results in missing leading zeroes when year <1000 #2230

Sharparam opened this issue Feb 7, 2023 · 1 comment · Fixed by #2231
Labels

Comments

@Sharparam
Copy link
Contributor

Describe the bug
If the year component of a date is less than 1000, the leading zeroes are omitted when trying to format the year with 'YYYY'.

E.g.:

dayjs(Date.parse('0001-01-01')).format('YYYY-MM-DD') //=> '1-01-01'
dayjs(Date.parse('0010-01-01')).format('YYYY-MM-DD') //=> '10-01-01'
dayjs(Date.parse('0100-01-01')).format('YYYY-MM-DD') //=> '100-01-01'

Expected behavior
'YYYY' in the format string should place leading zeroes to make sure the year takes up 4 digits in the output.

E.g.:

dayjs(Date.parse('0001-01-01')).format('YYYY-MM-DD') //=> '0001-01-01'
dayjs(Date.parse('0010-01-01')).format('YYYY-MM-DD') //=> '0010-01-01'
dayjs(Date.parse('0100-01-01')).format('YYYY-MM-DD') //=> '0100-01-01'

Information

  • Day.js Version: v1.11.7
  • OS: Windows 11
  • Browser Firefox, NodeJS console
  • Time zone: CET (UTC +1), Central European Time (Europe/Stockholm) (DST not in effect)
Sharparam added a commit to Sharparam/dayjs that referenced this issue Feb 7, 2023
Adds padding to the year component when formatted with `'YYYY'`, similar to how padding is handled for '`MM`' and '`DD`'.

Fixes iamkun#2230
@github-actions
Copy link

github-actions bot commented Jun 2, 2023

🎉 This issue has been resolved in version 1.11.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant