-
-
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] Timezone management fails with dayjs
id the timezone is UTC+00:00
#9653
Comments
Seems like changing all Does the time picker component not recognize all IANA time zones? |
dayjs
id the timezone is UTC+00:00
Thanks for reporting this issue. I can confirm it only occurs on TZ UTC+00:00 https://codesandbox.io/s/quirky-kapitsa-sspwx2?file=/demo.tsx About the following point
In v5 it ways accepting string. But internally it was simply doing something similar to So I'm not sure to get the link with the issue you are describing |
Right, I misspoke. We received unix in milliseconds from the server, converted it to string, then gave it to the date picker and it did all the rest of the magic and it worked that way. We used a custom "time picker," which was basically just a dropdown of times that a user can select. Now, everything is much easier and simpler just accepting a dayjs object as the currency of date and time. |
Unfortunately, it does not look like something we could easily solve. I did not manage to extract the bug in our codebase, and from dayjs repository issues, it seems they have a few issues about UTC+00:00 timezone
Should have a double look latter |
Thanks for looking into this. It does seem like a tricky one. I was seeing weird behavior with GMT+0 time zones, but there is a workaround for this particular problem (for the time being), and I'd like to run this by you to see if you see potential pitfalls. So for my app, the user specifies their own time zone via our app internals and we receive the time zone from the server in IANA format (i.e So what I do to "fix" this issue is I simply check whether or not the given time zone is GMT (which means It's as simple as this:
This works for me in all cases I tested. So I can simply do this:
Like I mentioned in my findings, if for example, instead of doing From the looks of everything, it works like it's supposed to. However, I'm not really a big fan of hackery and unsure if this could cause any unforeseen side effects I'm not aware of. |
How to set India timezone format |
@Mohan3298 Please refer to the timezone documentation. If you face an issue with it, open a distinct issue since it seems unrelated to this one Don't forget to upgrade to the latest version since its a recent feature |
It seems like the issue gets even weirder. If the DatePicker value is null and the initial timezone is GMT+, when you change the timezone to UTC or GMT-, it becomes broken too. playground: https://codesandbox.io/s/twilight-dust-pw5lcl?file=/src/DateTimePicker.js Screen.Recording.2023-09-05.at.16.27.16.movUpdate: If the new timezone is less than the previous one, the calendar becomes broken. For example, changing from America/Belize (GMT-6) to America/Chicago (GMT-5) is okay, but changing from America/Belize (GMT-6) to America/Creston (GMT-7) is broken. |
@alexfauquette I do have a fix for that! Will open a PR shortly! 💯 |
FYI: its not related to UTC. Any timezone that has |
I your fix regarding to my OP? Is it a mui issue or a dayjs issue? I have since switched to Moment and it's doing fairly well for the time being. |
@lemmylem the fix i am working on seems to be an issue with our adapter. the dates that get passed to the There is one fix i do have for the related issue from @SiarheiLazakovich (#9653 (comment)) |
Excellent work. I figured it was something to do with MUI but I didn't have the bandwidth to look through the source code and find the problem in much detail. Keep me posted as I'll be watching this thread in the meantime. Thanks again for your work! |
Hey @lemmylem I did investigate this a bit more in-depth and I discovered that the underlying issue is indeed caused by A short explanation: In my case using
which is clearly incorrect. This does affect the display of any picker component at the moment, so it is a much bigger issue than we anticipated at first. I am currently discussing steps we can take here with the team, so stay tuned. |
Hey @lemmylem I did take the time yesterday evening to investigate so I could push a fix to the dayjs repo. iamkun/dayjs#2481 Lets see when the maintainer gets to it. I hope this resolves all timezone formatting issues we currently have. |
Does this also cause a problem with duplicated dates? https://codesandbox.io/s/datepicker-with-dayjs-forked-f5y5j5?file=/src/App.js I see that removing |
Hey @Cheewbacca We do support timezones directly in the components. There is a dedicated section about it in our docs. Also consult our docs about the usage of UTC with dayjs here. |
The codesandbox is a valid usage of our timezone API I would suggest to avoid converting to a dayjs object during render and instead convert it in state (fixed example) But we still have the same bug. |
OH, yes ... DST is another issue with |
About daylight saving: #10584 |
Hello there, actually I have duplicated dates in the fixed example provided by you as @alexfauquette has. Maybe it is actually caused by DST, my timezone is 'Europe/Kiev'. Tag me if I can provide some more info or help with something else |
Yes, that's one I'm saying in the last sentence of my message. |
Since I've also stumbled upon issue with DST I will share a solution that is relatively easy:
myNewFunction(date) now returns Dayjs Object with applied DST, and we can manipulate it however we like. Works like a charm 😄 |
The update of dayJS lib to a version after v1.11.12 seems to fix the issue described here. #13919 bumps the version into our repo and potentially fixes this issue on a future relase. |
@arthurbalduini This fix doesn't seem to solve the problem (live example). DateTimePicker works well only when props If use relativeTime plugin, props When props
|
I tried to summarize the remaining UTC problems with Initial message by @lemmylem (link)
Comment by @SiarheiLazakovich (link)
Comment by @Cheewbacca (link)
|
Here is a reproduction case striped of all the MUI code for the time changing in the initial message: import dayjs, { Dayjs } from 'dayjs';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
dayjs.extend(utc);
dayjs.extend(timezone);
// 1. Date passed in props.value
const date = dayjs.utc('2023-04-17T15:30');
// 2. Date passed to `DayCalendar` with the rendered timezone
const dateWithTimezone = dayjs.tz(date, 'Africa/Bamako');
// 3. Date returned by `DayCalendar` to `DateCalendar` when clicking on the 1st day of the 2nd week
const firstDayOfSecondWeek = dateWithTimezone.startOf('month').startOf('week').add(7, 'day');
// 4. Date returned by `DateCalendar` to `usePickerValue`
let newDate = firstDayOfSecondWeek;
newDate = newDate.set('hour', dateWithTimezone.hour());
newDate = newDate.set('minute', dateWithTimezone.minute());
newDate = newDate.set('second', dateWithTimezone.second());
newDate = newDate.set('millisecond', dateWithTimezone.millisecond());
// 5. Date passed to `onChange` callback with the input timezone
const newDateWithInputTimezone = newDate.utc();
console.log(newDateWithInputTimezone.format('MM/DD/YYYY h:mm A')); We can replace the // 5. Date passed to `onChange` callback with the input timezone
// const newDateWithInputTimezone = newDate.utc();
const newDateWithInputTimezone = dayjs(new Date(newDate.valueOf()), {
locale: newDate.$L,
utc: true,
}); For me the problem is that the proto.valueOf = function () {
const addedOffset = !this.$utils().u(this.$offset)
? this.$offset + (this.$x.$localOffset || this.$d.getTimezoneOffset()) : 0
return this.$d.valueOf() - (addedOffset * MILLISECONDS_A_MINUTE)
} I'm in Running |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/recursing-fast-9n729n?file=/src/DateTimePicker.js
I have set up a date + time picker combo as a demo of the weirdness I'm seeing. I'm not entirely sure if this is a bug or not, but it's strange and it's happening using the
timezone
prop. At the very least, it's not the behavior I would expect to see. I'm not seeing these issues if I simply usedayjs.tz
and specify the time zone that way.Steps:
2023-04-17T15:30
, which translates to 3:30pm.timezone
prop ofAfrica/Bamako
, which is GMT) is displaying the wrong time (7:30PM)Current behavior 😯
When I first load the date and time picker, the time picker displays the wrong time value when I use it with
timezone
prop. However, then you click the icon and open the dialog, it holds the correct time value. When switching dates via the MUI date picker, the time values also change.Expected behavior 🤔
The time picker should display the correct value when configuring for a specific time zone. When time and date picker are used together, changing the date should only change the date, not the time value.
Context 🔦
I'm trying to update to the newest version of MUI, that includes the date time picker.
I have a custom date/time range picker solution for previous MUI version and trying to integrate the new time picker with the custom built one. One of the things that MUI has done is now with the new version, only the date time object is accepted. Before, it would accept strings and unix stamps.
Using
dayjs.tz
or setting a default time zone works as expected and I'm not seeing these issues. However, using thetimezone
prop doesn't work the same and I assume it's supposed to work the same.EDIT: I have done some additional testing and it seems like this is only observable for GMT time zones (offsets of 0).
Your environment 🌎
npx @mui/envinfo
Order ID or Support key 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: