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

Use Intl API for guessing when available #291

Merged
merged 2 commits into from
Mar 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions moment-timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@
}

function rebuildGuess () {

// use Intl API when available and returning valid time zone
if (typeof Intl === 'object' && isFunction(Intl.DateTimeFormat)) {
var zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (zone && (zone.indexOf("/") > -1 || zone === 'UTC')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like if (typeof zone === 'string' && names[normalizeName(zone)]) { to make sure a identifier returned from Intl actually has data loaded? Maybe we could add a logError if Intl returns an identifier that was not loaded in the data set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I like that idea. I'll work on that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I continued this work in #304

return zone;
}
}

var offsets = userOffsets(),
offsetsLength = offsets.length,
guesses = guessesForUserOffsets(offsets),
Expand All @@ -344,6 +353,10 @@
return cachedGuess;
}

function isFunction(input) {
return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
}

/************************************
Global Methods
************************************/
Expand Down