-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add missing padding to 'YYYY' format #2231
Conversation
Adds padding to the year component when formatted with `'YYYY'`, similar to how padding is handled for '`MM`' and '`DD`'. Fixes iamkun#2230
Thanks, can you add some relevant unit test,s please |
Codecov Report
@@ Coverage Diff @@
## dev #2231 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 181 183 +2
Lines 2074 2111 +37
Branches 544 555 +11
=========================================
+ Hits 2074 2111 +37
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Added two tests: one to explicitly check that year 1 gets padded with zeroes on formatting, and one test to make sure the formatting matches how moment does it. |
THX |
## [1.11.8](v1.11.7...v1.11.8) (2023-06-02) ### Bug Fixes * .format add padding to 'YYYY' ([#2231](#2231)) ([00c223b](00c223b)) * Added .valueOf method to Duration class ([#2226](#2226)) ([9b4fcfd](9b4fcfd)) * timezone type mark `date` parameter as optional ([#2222](#2222)) ([b87aa0e](b87aa0e)) * type file first parameter date is optional in isSame(), isBefore(), isAfter() ([#2272](#2272)) ([4d56f3e](4d56f3e))
🎉 This PR is included in version 1.11.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Should there be an option for maybe just |
@bensaufley I'm not sure what datetime libs you're familiar with, but this behaviour is consistent with how all major libraries behave, including JavaScript itself. |
All fair points, but:
I absolutely agree that |
It's true that it's technically a breaking change. However, given that it is a bug fix for unexpected behaviour (see below note about the docs), I think it being part of a patch bump is reasonable. It could be useful to add
While moment does not have It's also worth noting that the docs for dayjs has claimed (I'm also willing to bet that a majority of users would expect |
All sounds good to me and I agree with most or all of your points. I don't have a strong preference but I do think it would probably be good, if probably an edge case (in the same way that people probably mostly didn't encounter this issue), to support non-padded full year in one way or another. |
## [1.11.8](iamkun/dayjs@v1.11.7...v1.11.8) (2023-06-02) ### Bug Fixes * .format add padding to 'YYYY' ([iamkun#2231](iamkun#2231)) ([00c223b](iamkun@00c223b)) * Added .valueOf method to Duration class ([iamkun#2226](iamkun#2226)) ([9b4fcfd](iamkun@9b4fcfd)) * timezone type mark `date` parameter as optional ([iamkun#2222](iamkun#2222)) ([b87aa0e](iamkun@b87aa0e)) * type file first parameter date is optional in isSame(), isBefore(), isAfter() ([iamkun#2272](iamkun#2272)) ([4d56f3e](iamkun@4d56f3e))
## [1.11.8](iamkun/dayjs@v1.11.7...v1.11.8) (2023-06-02) ### Bug Fixes * .format add padding to 'YYYY' ([#2231](iamkun/dayjs#2231)) ([00c223b](iamkun/dayjs@00c223b)) * Added .valueOf method to Duration class ([#2226](iamkun/dayjs#2226)) ([9b4fcfd](iamkun/dayjs@9b4fcfd)) * timezone type mark `date` parameter as optional ([#2222](iamkun/dayjs#2222)) ([b87aa0e](iamkun/dayjs@b87aa0e)) * type file first parameter date is optional in isSame(), isBefore(), isAfter() ([#2272](iamkun/dayjs#2272)) ([4d56f3e](iamkun/dayjs@4d56f3e))
Adds padding to the year component when formatted with
'YYYY'
, similar to how padding is handled for'MM'
and'DD'
.Fixes #2230