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

[fields] Improve the check for year in doesSectionFormatHaveLeadingZeros #17051

Merged
merged 6 commits into from
Mar 21, 2025

Conversation

flaviendelangle
Copy link
Member

Fixes #17047

I can't reproduce with date-fns-jalali v3, but I think this test is more robust anyway.

@flaviendelangle flaviendelangle self-assigned this Mar 20, 2025
@flaviendelangle flaviendelangle added bug 🐛 Something doesn't work component: pickers This is the name of the generic UI component, not the React module! labels Mar 20, 2025
Copy link

Thanks for adding a type label to the PR! 👍

@flaviendelangle flaviendelangle changed the title [fields] Improve the check for year in doesSectionFormatHaveLeadingZeros [fields] Improve the check for year in doesSectionFormatHaveLeadingZeros Mar 20, 2025
@flaviendelangle flaviendelangle added needs cherry-pick The PR should be cherry-picked to master after merge v7.x labels Mar 20, 2025
@mui-bot
Copy link

mui-bot commented Mar 20, 2025

Deploy preview: https://deploy-preview-17051--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 542cfbc

@@ -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;
Copy link
Member Author

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

@LukasTy LukasTy added the v6.x label Mar 20, 2025
Copy link
Member

@LukasTy LukasTy left a 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 },
Copy link
Member

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.

Copy link
Member Author

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 😆

Copy link
Member Author

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 🤦

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

For me it's a bug on dayjs side because they clearly state it should have to digits, so console.log(dayjs().set('year', 9).format('YY')) should return 09

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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

Copy link
Member

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 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

@flaviendelangle flaviendelangle merged commit aef6d43 into mui:master Mar 21, 2025
22 checks passed
@flaviendelangle flaviendelangle deleted the jalali-yyyy branch March 21, 2025 09:36
Copy link

Cherry-pick PRs will be created targeting branches: v6.x, v7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: pickers This is the name of the generic UI component, not the React module! needs cherry-pick The PR should be cherry-picked to master after merge v6.x v7.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pickers] maxDigitNumber error on AdapterJalali in Jalali calendar system
4 participants