Skip to content

Conversation

@timrwood
Copy link
Member

This adds the ability to guess the user's timezone.

moment.tz.guess(); // America/Chicago

The guessing is based on the user offset and zone abbreviation over a handful of moments. We use Jan 1 and July 1 from the 2 years before and after the current year. We also do a binary search to find the exact time the user's timezone changed, and use moments just before and after the transition.

Once we have this data about the user's environment, we compare it to our known timezones. The timezone that is closest to the user's environment wins.

Due to links and timezones that appear similar in recent years, there are often a handful of timezones that appear to match. We maintain a list of approximate populations for each timezone's largest city, and use that as a tie-breaker.

timrwood added a commit that referenced this pull request Dec 28, 2015
@timrwood timrwood merged commit d72f95c into develop Dec 28, 2015
@timrwood timrwood deleted the guess-timezone branch December 28, 2015 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants