Consider jsTimeZoneDetect
Closed this issue · 8 comments
The existing mechanism only bases its guess on the current offset (js: new Date().getTimezoneOffset()
). You may want to consider using jsTimeZoneDetect instead.
@adamcharnock what do you think?
This is a great idea. Using the offset to select the timezone is problematic because not all timezones use daylight savings time and therefore the timezone that is guessed may only be correct for part of the year. For example I am in America/Los_Angeles time (UTC -7 or -8 depending on the time of year), however my timezone is autodetected as America/Phoenix time (always UTC -7).
FWIW - Moment.js also has this now in moment-timezone with moment.tz.guess()
Massively late reply to this one: I'm in favour of this, although it would be best if were not a mandatory dependency on either library. If, 2 years on, you are still interested in filling a pull request then I'd be happy to receive it.
Why not Intl.DateTimeFormat().resolvedOptions().timeZone
?
This is how moment-timezone "detects" a TZ. https://github.com/moment/moment-timezone/blob/d7f687ea598b205806decd83b78d3ea9ad11a569/moment-timezone.js#L356
If that fails, fall back to the current method for getting a TZ
Indeed, with the current state of the world, I would recommend just using Intl
.
@bashu @adamcharnock As requested I created a PR for this: #63
It will prefer the timezone and falls back to offset. Let me know if there are more improvements needed.