-
Notifications
You must be signed in to change notification settings - Fork 47
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
Feature request: Automatically detect user timeZone based on GMT offset #25
Comments
Hey thanks for bringing this up! So if I understand you correctly, you want to be able to pass in a GMT offset (i.e. |
So the usecase is that we want to default select option to the applicable timeZone according to the user browser settings; this would work if the timeZone selection included all the timeZones that exist, but that list is very user unfriendly ux wise (hense we use this select). But we'd still like to be able to default the applicable select option based on user browser configuration. So like: |
Ah okay, so we can probably relatively easily select the default timezone via the users browser language / country headers or something like that. Would that fulfill your use case? |
How's this?
I don't think this works in IE11 though. |
Yeah just putting it as the default value in the useState call is what I would have done too. I didn't know the new Regarding IE11, thats okay I dont plan on going out of my way to support that anyway.. |
Hey so I've released a new version last night with a bunch of clean up. Wasn't sure whether to put this into a prop the user could enable (i.e. But just decided to throw it in the readme for now since it makes more sense for the user to use your little Thanks again for the tip! |
@ndom91 You are very welcome. Thanks for making a wonderful open source component 😄 |
Going to close this for now, if anyone comes across this looking for similar behavior - checkout @ndrwksr 's workaround in the comment above (#25 (comment)), or in the README. |
@ndom91 What I meant was what happens in the case the timezone is missing from the select. Attached a screenshot of what happens when the timeZone detected is Europe/Rome. Added after initial comment: So Intl.DateTimeFormat().resolvedOptions().timeZone is a good way to do it, but then the missing piece of the puzzle is somehow - and I'm not quite sure what the appropriate solution is here - map back to one of the options within react-timezone-select. |
Ah gotcha. Yeah so there's two ways to deal with this. Either I expand the interior map to include every timezone in that "Europe/Rome" format. Or I make this "setUserTimezoneByDefault" thing an internal prop, and then I can match user timezones that don't exist (like Europe/Rome) by offset to the matching existing choice (Europe/Berlin or Europe/Amsterdam I think it'd be). What do you think? I'm up for doing the second variant, that shouldn't be too hard. And doesn't change the user facing api other than adding a new boolean prop. |
The Dumb approach I came up with is to indeed get a list together of all timezones in existance, and map them to the relevant "Short list". I think it is desireable from this component POV to deal with valid timezones that are not part of the component display (in case people want to do this). I was wondering if there were smarter ways like detecting an entered timezone GMT offset, and then find the item in the list with the same GMT offset rules. By logic, I think this belongs within the |
@emrysal I believe this would be helpful: |
Btw @emrysal - regarding the union type |
Hey everyone, @emrysal's PR to match any possible timezone to one in our list, has been merged! 🎉 This means you can safely use the |
There is a problem with using |
Yeah this is a known issue, someone has suggested auto detecting the city and generating the timezones dynamically in this issue, but no movement yet. |
We've got a usecase where we want the use the dayjs.tz.guess() function, which for Italy for example may return Europe/Rome. This wouldn't resolve to anything in this case.
Perhaps it is an idea to do some kind of map of GMT offset to timeZone?
The text was updated successfully, but these errors were encountered: