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 user timezone #285

Merged
merged 16 commits into from
Dec 28, 2015
Merged

Guess user timezone #285

merged 16 commits into from
Dec 28, 2015

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.

1 participant