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

[pickers] fix the issue of the timezone change in Day calendar #12256

Closed

Conversation

shaharyar-shamshi
Copy link
Contributor

fixes #12195

@shaharyar-shamshi
Copy link
Contributor Author

shaharyar-shamshi commented Feb 28, 2024

Example code

import * as React from 'react';
import { DemoContainer } from '@mui/x-date-pickers/internals/demo';
import { LocalizationProvider } from '@mui/x-date-pickers-pro';
import { AdapterDayjs } from '@mui/x-date-pickers-pro/AdapterDayjs';
import { DateRangeCalendar } from '@mui/x-date-pickers-pro/DateRangeCalendar';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';

dayjs.extend(utc);
dayjs.extend(timezone);

export default function BasicDateRangeCalendar() {
  const [time, setTime] = React.useState('UTC');

  return (
    <>
      <div>
        <select onChange={(event) => setTime(event.target.value)}>
          <option value="UTC">UTC</option>
          <option value="America/New_York">America/New_York</option>
        </select>
      </div>
      <LocalizationProvider dateAdapter={AdapterDayjs}>
        <DemoContainer components={['DateRangeCalendar']}>
          <DateRangeCalendar timezone={time} />
        </DemoContainer>
      </LocalizationProvider>
    </>
  );
}

import * as React from 'react';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';

dayjs.extend(utc);
dayjs.extend(timezone);

export default function BasicDateCalendar() {
  const [time, setTime] = React.useState('UTC');
  return (
    <>
      <div>
        <select onChange={(event) => setTime(event.target.value)}>
          <option value="UTC">UTC</option>
          <option value="America/New_York">America/New_York</option>
        </select>
      </div>
      <LocalizationProvider dateAdapter={AdapterDayjs}>
        <DateCalendar timezone={time} />
      </LocalizationProvider>
    </>
  );
}

@mui-bot
Copy link

mui-bot commented Feb 28, 2024

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

Generated by 🚫 dangerJS against a340814

@shaharyar-shamshi
Copy link
Contributor Author

shaharyar-shamshi commented Feb 28, 2024

@LukasTy @michelengelen It seems to work I did some manual testing on this two example if you can also help in checking manually it would be great help. It is just sanity testing to check whether I am proceeding in right direction and didn't miss any case.

I will add the test cases later.

Q) Why I consider this two example only ?
Answer) because DateCalendar and DateRangeCalendar internally uses DayCalendar

@shaharyar-shamshi shaharyar-shamshi changed the title fix the issue of the timezone change in Day calendar [pickers] fix the issue of the timezone change in Day calendar Feb 29, 2024
@shaharyar-shamshi shaharyar-shamshi marked this pull request as draft February 29, 2024 13:36
@shaharyar-shamshi shaharyar-shamshi force-pushed the hotfix/DatePicker-timezone branch from 3edc491 to 33f17cc Compare February 29, 2024 15:13
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 29, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 29, 2024
@shaharyar-shamshi shaharyar-shamshi force-pushed the hotfix/DatePicker-timezone branch 2 times, most recently from c27e5b8 to 8f31c76 Compare February 29, 2024 19:09
@shaharyar-shamshi shaharyar-shamshi force-pushed the hotfix/DatePicker-timezone branch from cf64f7b to 0579906 Compare February 29, 2024 20:18
@shaharyar-shamshi
Copy link
Contributor Author

shaharyar-shamshi commented Mar 1, 2024

@LukasTy @michelengelen It seems to work I did some manual testing on this two example if you can also help in checking manually it would be great help. It is just sanity testing to check whether I am proceeding in right direction and didn't miss any case.

I will add the test cases later.

Q) Why I consider this two example only ? Answer) because DateCalendar and DateRangeCalendar internally uses DayCalendar

@michelengelen @LukasTy if you can check it

@shaharyar-shamshi shaharyar-shamshi force-pushed the hotfix/DatePicker-timezone branch from ec3573c to 00887cc Compare March 1, 2024 17:26
@shaharyar-shamshi shaharyar-shamshi marked this pull request as ready for review March 1, 2024 22:15
@shaharyar-shamshi shaharyar-shamshi force-pushed the hotfix/DatePicker-timezone branch from acfe590 to 4da767d Compare March 2, 2024 23:30
@shaharyar-shamshi shaharyar-shamshi force-pushed the hotfix/DatePicker-timezone branch from 7217396 to b7122a7 Compare March 3, 2024 07:22
@shaharyar-shamshi
Copy link
Contributor Author

@LukasTy If you can kindly review the PR. I assume argos failing test can be ignored as current image is correct.

@LukasTy
Copy link
Member

LukasTy commented Mar 4, 2024

@shaharyar-shamshi Thank you for taking your time on this issue.
I'm looking into it to identify if a bit more proper solution could be applied.
This looks like a fix for this one condition, it works and that's great, but we still don't know where else we might have a problem with the timezone not being updated when it is changed. 🙈

@shaharyar-shamshi
Copy link
Contributor Author

@shaharyar-shamshi Thank you for taking your time on this issue. I'm looking into it to identify if a bit more proper solution could be applied. This looks like a fix for this one condition, it works and that's great, but we still don't know where else we might have a problem with the timezone not being updated when it is changed. 🙈

I think problem is more of how we manage the timezone change. Timezone in itself work but major problem is how we are actually using that changed timezone.

For example in this example timezone change was working correctly but we were not correctly handling the returned result by normalization.

I am also checking other places where we might encounter similar kind of issue with timezone.

@LukasTy
Copy link
Member

LukasTy commented Mar 4, 2024

@shaharyar-shamshi I've created a PR (#12321), which, I think, solves the problem in a bit more reliable and correct way.
I think it supersedes this PR.
Feel free to check and review it. 😉

@zannager zannager added the component: pickers This is the name of the generic UI component, not the React module! label Mar 4, 2024
@zannager zannager requested a review from LukasTy June 6, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pickers] Unable to set timezone in DatePicker
4 participants