-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[pickers] Fix AdapterMomentJalaali
regression
#13144
Conversation
@@ -766,6 +766,17 @@ async function initializeEnvironment( | |||
// expect(await status.isVisible()).to.equal(true); | |||
// expect(await status.textContent()).to.equal('Submitted: 04/17/2022'); | |||
// }); | |||
|
|||
it('should correctly select a day in a calendar with "AdapterMomentJalaali"', async () => { |
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 wasn't able to make a unit test work in a reasonable amount of time. 🙈
// `isSame` seems to mutate the date on `moment-jalaali` | ||
// @ts-ignore | ||
return value.clone().isSame(comparing, 'jMonth'); | ||
return value.jYear() === comparing.jYear() && value.jMonth() === comparing.jMonth(); |
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.
This is the main problem that was causing the behavior, because it is called here:
mui-x/packages/x-date-pickers/src/DateCalendar/useCalendarState.tsx
Lines 71 to 74 in 6c4308f
const needMonthSwitch = | |
action.focusedDay != null && | |
!disableSwitchToMonthOnDayFocus && | |
!utils.isSameMonth(state.currentMonth, action.focusedDay); |
And it caused the focus to be changed to the first day of the current month.
Deploy preview: https://deploy-preview-13144--material-ui-x.netlify.app/ Updated pages: |
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.
With those methods I would be very careful with timezone
Could you check if we have tests on those adapter methods for edge cases where you are in the same year when converted to the same timezone but different years in each date's original timezone?
@flaviendelangle This particular adapter is not timezone compatible. 🤔
|
Right... But that's probably not important indeed 😆 |
<LocalizationProvider dateAdapter={AdapterMomentJalaali} adapterLocale="fa"> | ||
<DateTimePicker | ||
label="AdapterMomentJalaali" | ||
defaultValue={moment('2022-02-01T12:00:00')} |
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.
date-fns-jalaali
defaults to 12hr clock, whereas moment-jalaali
to 24hr clock.
I set both to mid-day to at least have them show 12:00
.
Do you have better suggestions?
Maybe force ampm
to false
or true
on both? 🤔
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 sure if adding an exception to our AMPM management to fix this inconsistency is worth it
I think your test is nice and we can keep the behavior as it is
Does it really work if the component re-renders? |
@flaviendelangle I've tried going back and forth multiple times between the demo pages (jalali and Moment UTC) and changing the demos to trigger some issue, but I couldn't do it... 🤔 🤷 I would expect problems if those demos were on the same page, but it seems "fine" in the current state. 🙈 🤷 P.S. Only after ca1e423 commit argos (test:regressions) is finally happy and no longer detects those previously seen problems. 😉 |
No |
I'm quite unhappy with the solution as well, but on the other hand, if we have problems—we can reconsider having this demo or moving it somewhere else. |
Fixes #12794
Add a docs example with
moment-jalaali
.The
isSameYear
and especially theisSameMonth
methods seemed incorrect.Replaced with this approach:
https://github.com/dmtrKovalenko/date-io/blob/634ae738fa70545ad5fa954861a5e5498b4affc6/packages/jalaali/src/jalaali-utils.ts#L229-L235
The culprit of the regression is: https://github.com/mui/mui-x/pull/8789/files#diff-de14e1bc65d9c2f3084b3e07420b775d6bdcd1fb6b2538dc02745ab862b4a998R185-R189