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

Guess should ignore Intl detection bad results #423

Closed
jou opened this issue Nov 24, 2016 · 3 comments
Closed

Guess should ignore Intl detection bad results #423

jou opened this issue Nov 24, 2016 · 3 comments

Comments

@jou
Copy link

jou commented Nov 24, 2016

Sometimes, the Internationalization API doesn't return sensible values. I encountered that in Chrome for Android, where it returns "CET" instead of a timezone ID when the selected system timezone is using Central European Time.

Currently, I'm removing Intl.DateTimeFormat before calling moment.tz.guess(true) again. That's not really a nice solution, so can an option be added to bypass it?

@SuperMario77
Copy link

SuperMario77 commented Nov 24, 2016

I also vote for such an option. I work on a cordova app on Windows 10 tablet and there the Microsoft Edge Browser Engine will be used. I noticed that the call to "Intl.DateTimeFormat().resolvedOptions().timeZone" always returns a cached value.

Steps to reproduce the problem:

  1. Start Microsoft Edge on Window 10 machine
  2. Enter Javascript Console by pressing F12 and execute this command:
    Intl.DateTimeFormat().resolvedOptions().timeZone
  3. The timezoneId should match the currently set timezone of your system
  4. Change your system timezone to another timezone
  5. Execute again this command:
    Intl.DateTimeFormat().resolvedOptions().timeZone
  6. The timezoneId is still the same from the first call. <= Cached result? Bug?

This procedure works in Chrome without problems. Chrome noticed the changed timezone. So Microsoft has a bug or a "cache feature" ;-) in his Intl.DateTimeFormat() implementation. And because moment-timezone uses this Intl Feature, the moment.tz.guess(true) method also returns the wrong timezone in my cordova app (Edge Browser Engine).

If I remove the Intl Feature at the beginning by doing:
Intl.DateTimeFormat = undefined;

then moment-timezone always guesses the correct timezoneId in my win 10 cordova app.

@mattjohnsonpint
Copy link
Contributor

I'm not concerned about the cached part. Various browsers have gone either way on that over the years. If you're concerned about that, raise an issue with Edge / ChakraCore.

I do think it would be good to make sure Intl returned a zone with a / char in it (or UTC) before accepting the results. Note, jsTimeZoneDetect had a similar issue.

For now, you could simply remove (or don't add) the zones that use three-letter abbreviations instead of full identifiers.

@mattjohnsonpint mattjohnsonpint changed the title Add option to bypass Internationalization API in moment.tz.guess() Guess should ignore Intl detection bad results Nov 28, 2016
@mattjohnsonpint
Copy link
Contributor

To clarify - a true/false option isn't very useful IMHO, but ignoring bad results is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants