-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[fields] Improve the check for year in doesSectionFormatHaveLeadingZeros
#17051
Conversation
Thanks for adding a type label to the PR! 👍 |
doesSectionFormatHaveLeadingZeros
Deploy preview: https://deploy-preview-17051--material-ui-x.netlify.app/ |
@@ -195,8 +195,7 @@ function adjustSectionValue<TValue extends PickerValidValue>( | |||
const step = | |||
section.type === 'minutes' && stepsAttributes?.minutesStep ? stepsAttributes.minutesStep : 1; | |||
|
|||
const currentSectionValue = parseInt(removeLocalizedDigits(section.value, localizedDigits), 10); | |||
let newSectionValueNumber = currentSectionValue + delta * step; | |||
let newSectionValueNumber: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related, it was just weird to generate NaN
on newSectionValueNumber
and then not use it, I lost some time debugging because of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and quick fix. 👍 🎉
This looks like an issue even on v6... 🤷
Not sure how it could have started happening if we didn't update anything there, but I added v6.x
label to create a cherry-pick to that branch, because technically it could be seen as a "regression" that might be worth fixing. 🙈
@@ -28,7 +28,7 @@ type Constructor = (...args: Parameters<typeof defaultDayjs>) => Dayjs; | |||
|
|||
const formatTokenMap: FieldFormatTokenMap = { | |||
// Year | |||
YY: 'year', | |||
YY: { sectionType: 'year', contentType: 'digit', maxLength: 2 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be related, but I noticed on vitest an error that could only be fixed by adding
yy: { sectionType: 'year', contentType: 'digit', maxLength: 2 },
to AdapterDateFnsBase
.
I don't understand why this is the case or why the tests were failing only in vitest, so if you create a fix let me know, otherwise I'll isolate the change into a PR later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log(dayjs().set('year', 2009).format('YY')); // 09
console.log(dayjs().set('year', 9).format('YY')); // 9
I don't want to leave on this planet anymore 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep this for a follow up
But yy: { sectionType: 'year', contentType: 'digit', maxLength: 2 },
causes a bug as well... you can't enter a year below 9
because dayjs can't parse 9
for the token YY
🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/iamkun/dayjs/blob/45f88334d08f8278e51b8189671ddea4720c754e/src/index.js#L287
I think the fix is super simple here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment was regarding the DateFns adapter, not dayjs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, in that case if you can extract it 🙏 , I'll have a look at it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it was fixed after merging master in 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
b29774d
to
542cfbc
Compare
Cherry-pick PRs will be created targeting branches: v6.x, v7.x |
Fixes #17047
I can't reproduce with date-fns-jalali v3, but I think this test is more robust anyway.