-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Not able to set default time zone for DatePicker and TimeInput #3432
Comments
This issue is still present with the @mantine/dates 6.0 overhaul. If mantine is to use It could be decided that dealing with timezones that are different than the browsers timezone is out of scope, but this seems like a pretty significant limitation for apps that deal with objects across timezones. I propose adding an optional @rtivital any objections to a PR? |
You are welcome to submit a PR with |
Would you also be open to adding a prop to all relevant components? I suppose that could be done as a second stage |
I think timezone on DatesProvider is enough |
Hi, is there any update to this? or will this be addressed with the v7 rework? |
There is no rework of the dates package in v7. If you are interested in contributing this feature, you can submit a PR in mantine-v7 repo |
It is incomplete and abandoned |
i'll take a look at it, currently dayjs and timezones is a little bugged (iamkun/dayjs#2398 and many more). do you have any idea to implement timezones easily? or will it just be a bigger rework? as i think this has to be implementet in may of the components.? |
Unfortunately the temporal API hasn't landed yet, but it would be a good API for this |
would be switching form exposing Date objects to dayjs objects? this will be a breaking change. it may be possible to expose date objects for the components, but as you also export helper funtions this will be very hard for them. |
I was referring to the (currently) stage 3 TC39 proposal (https://tc39.es/proposal-temporal/docs/) which has a much better API than Contrary to its name, The implementation approach taken in #3823 (which I have not had time to finish) attempts to resolve this pain point by introducing a timezone in the mantine context and mapping created Date objects from the browsers timezone to the given timezone (if it exists). It's error prone and hard to enforce that this is done everywhere correctly because every dayjs object has to be constructed from the context which is easy to forget. I still think this would be a great addition to the mantine dates library though due to its backwards compatibility. The temporal API introduces several new distinct objects to handle the complexity involved. For instance, it has As you say, it would also be possible to return Since the temporal API is not production ready yet, I don't think it makes sense to introduce this to mantine proper yet. It's possible to create wrapping components however, and it may make sense to have a distinct library in the meantime that utilizes a polyfill. This is the direction I will likely take my code base and if I end up with something generally usable I will publish it as a distinct library. |
@benlongo i haven't tried the wrapper approach, wich may work, but produces an overhead instead of just mantine supporting this. the main problem is, that mantine uses the plane You are right, temporal api would be a nice thing, but do you think it will be usable soon. i can't find anything about the release timeline of this. |
One approach would be to use plain date strings as properties of the date picker and use dayjs internally. |
@ArnaudValensi this would have been my approach, but it would stille be a breaking change as mantine exports helper functions like Exporting the date for the components would be possible, but doing this for all the helper function will be a bit too much i think. especially as the recreation of the dayjs objects will take calculation time too. |
@ArnaudValensi I think the string approach as a baseline could work well. Various wrapping layers/components (Dayjs, Date, Temporal, etc.) could be created on-top of it. For backwards compat, the |
i added a MR to the v7 repo, i hope this will work for you. i introduced some kind of date "shift" to handle timezones without any breaking changes. @rtivital |
merged and released to 7.0.0-beta.6 rtivital/mantine-v7#59 |
This issue is closed for one of these reasons:
If you think that this issue was closed by mistake and it is still an issue in version 7.0, please reopen it. |
What package has an issue
@mantine/dates
Describe the bug
All the dates displayed by the DatePicker and TimeInput are in the local timezone. There is no way to display it using a custom timezone, like UTC for example.
What version of @mantine/hooks page do you have in package.json?
5.10.2
Some comments
Date object always store absolute dates inside, this is when we use the function toString or the functions to get any of the component that it does the shift based on the local timezone. TimeInput just uses those functions to display the dates, so it is not possible to display a date as UTC for example without creating fake dates.
Right now the only solution I have is to do this:
Note that the dates created with the shift functions are date that are not representing the real time we manipulate. This is why having a way to select the timezone in the DatePicker and TimeInput components would be better.
Also, this code is bugged, it uses the current UTC offset, but the offset changes depending on the daylight saving in some countries. So if we are in winter and I want to select an UTC date in summer, this solution will give me an incorrect date.
The text was updated successfully, but these errors were encountered: