-
-
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
[pickers] Fix DateCalendar
timezone management
#12321
Conversation
DateCalendar
timezone management
Deploy preview: https://deploy-preview-12321--material-ui-x.netlify.app/ |
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.
Added some tentative review. will check further by running it.
screen.getAllByRole('gridcell', { | ||
name: (_, element) => element.nodeName === 'BUTTON', | ||
}).length, | ||
).to.equal(30); |
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 think the correct assertion should be number of grid cell of type button before and after the timezone change should be same. (I assume for month of february and month having 31 days it might fail)
and more accurate way of doing this will be before the the timezone change create the map of index of date in gridcell and compare it after the timezone change
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.
Thanks for noting. 🙏
I've seen your tests and do agree that they are more "complete", but IMHO, I don't see the benefit of having a more complex-to-read test with marginally stricter assertions. The main thing that we need to assert here is that the same amount of days have been rendered after a timezone switch. 🤔
I do value the benefit of simple tests, which you can glance over and understand in seconds. 🙈
What do you think?
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 totally agree simple is better. But there might be chance in month of july and August also december 2024 and January 2025 when consecutive months have equal number of dates then this might not cover those edge cases.
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.
But there might be chance in month of july and August also december 2024 and January 2025 when consecutive months have equal number of dates then this might not cover those edge cases.
Why do you think like that? 🤔
The test is set to use 1
calendar for simplicity and ("current") time is mocked to 2022-06-15
.
Maybe you are talking about a separate issue (#10584) with AdapterDayjs and DST?
That's a separate topic that I'm looking into. 😉
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.
No I am not talking about DST. although I missed the date mocking part. I assume it would render the calendar of current.
With date mocking your test will work.
Sorry for missing date mocking part.
I think this is bug
packages/x-date-pickers/src/DateCalendar/tests/DateCalendar.test.tsx
Outdated
Show resolved
Hide resolved
} | ||
render(<DateCalendarWithControlledTimezone />); | ||
|
||
expect( |
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.
same as above you can check my PR I have done in same way
I think there is some bug in BasicDateRange selecting any range (let's assume 12 March to April 21) having America/New_York as the timezone now change the timezone to UTC there is no change in the range of the calendar. also when switching while you will notice some flicker. Same is happening with the DateCalendar |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Hello all, just checking in on this and trying to understand where things are at timeline wise. It looks like this PR fixes an issue I ran into a while ago, so I'm looking forward to this being merged. Is this PR unable to be merged because there is a dependency on a fix for this other bug? Thanks for any info you can provide! |
Hey @jesse-garrison-panther, this PR fixes your mentioned problems. |
@LukasTy Thanks for the clarification! It would be great if this fix could go out separately from the DST issue you mentioned, although I don't have enough context around that other issue and how it might affect this fix. If they can both be fixed in a similar timeline, that's fine too. I just know personally I've been looking forward to using a new DatePicker component our team built, but the bug I originally filed is preventing us from using it until it's fixed. Thanks for all the great work you and the team is providing with MUI though! |
9007ca4
to
f36ed3a
Compare
React.useEffect(() => { | ||
dispatch({ | ||
type: 'changeMonth', | ||
newMonth: utils.startOfMonth(referenceDate), |
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.
Are we sure this change is wanted?
From what I can understand it will reset the displayed month to referenceDate
, so if the user had moved to another month and then the timezone changes it might be weird.
Tbh this is really an edge case and I could understand that we don't want to optimize for it
More problematic, this will break if the component re-renders and referenceDate
is passed directly is not memoized (which we support for now and we should keep supporting IMHO):
import * as React from 'react';
import dayjs from 'dayjs'
import Stack from "@mui/material/Stack";
import Switch from "@mui/material/Switch";
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';
export default function BasicDateCalendar() {
const [isActive, setIsActive] = React.useState(false)
return (
<Stack spacing={2}>
<Switch value={isActive} onChange={event => setIsActive(event.target.checked)} />
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DemoContainer components={['DateCalendar']}>
<DateCalendar referenceDate={dayjs('2022-04-17')} />
</DemoContainer>
</LocalizationProvider>
</Stack>
);
}
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.
@flaviendelangle WDYT about the updated solution: f859853?
It would update only the timezone
and optionally in some cases the month
(to avoid changing the month when switching timezone to -the current one
). I.e. America/New_York
-> America/Los_Angeles
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.
From what I understand, of the two problems I describe above, the 1st one still occurs but the 2nd does not, right?
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.
Were you able to replicate the first mentioned problem?
It does not happen to me. 🤔
This part: https://github.com/mui/mui-x/pull/12321/files#diff-b671464bcd4d0027334e53087da5e27c98342ac1c23b1550a4556879d6f20300R64-R66 is to ensure that the month doesn't shift when timezone
changes to a minus offset.
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.
Change the month to be July using the arrows, then click on "Change timezone".
It should move back to April.
The funny thing is, we already have this behavior on master (I would have thought otherwise), so no regression in your PR 👍
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.
That's a bit strange behavior that might be worth investigating a bit more in-depth.
I'm a bit puzzled why the current month doesn't change when the current month is changed to May
(+1). 🤔
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 a clue 😆
If you can create an issue and add it to the board so that we don't loose track of it
I don't think it's the top priority right now but I agree it would be interesting to understand what is going on
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Hello all, I'm just following up on this issue to see if there is a timeline of when it's expected to be merged? We've built a new date picker component that we're waiting to use, but this bug is currently a blocker. FWIW, we're also part of the Pro Plan. Thanks for any updates you can provide! 🙏 |
@jesse-garrison-panther Thank you for bringing this topic up. |
@LukasTy Thanks for the reply. Yes, I think that timeframe will work. |
@@ -54,6 +55,21 @@ export const createCalendarStateReducer = | |||
isMonthSwitchingAnimating: !reduceAnimations, | |||
}; | |||
|
|||
case 'changeMonthTimezone': { |
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'm not convinced by the name of this action.
If it runs every time the referenceDate
updates, could it be named changeReferenceDate
?
Or if we want to keep the focus on the month, changeCurrentMonthIfTimezoneChanged
?
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.
If it runs every time the
referenceDate
updates, could it be namedchangeReferenceDate
?
I don't have a strong preference for the action name.
It depends on how we look at the naming:
- Should it refer to what triggered the action?
- Should it refer to what the action will do?
Or if we want to keep the focus on the month,
changeCurrentMonthIfTimezoneChanged
?
But essentially, it does not change the currentMonth
most of the time, unless it would cause the month to change because of a timezone change. 🤔
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.
If you pass the timezone dirrectly to changeMonthTimezone
instead of passing the new month, the name and its behavior would then be coherent IMHO
Fixes #10804.
Fixes #14453.
Closes #12256
The
referenceDate
andcalendarState.currentMonth
were not updating when thetimezone
prop changes.Changed to:
referenceDate
value when the providedreferenceDate
or timezone prop changecalendarState.currentMonth
timezone whenreferenceDate
changes