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

Checking for undefined Intl.DateTimeFormat().resolvedOptions().timeZone #322

Merged
merged 1 commit into from
May 3, 2016
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions moment-timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@
// use Intl API when available and returning valid time zone
try {
var intlName = Intl.DateTimeFormat().resolvedOptions().timeZone;
var name = names[normalizeName(intlName)];
if (name) {
return name;
if (intlName){
var name = names[normalizeName(intlName)];
if (name) {
return name;
}
logError("Moment Timezone found " + intlName + " from the Intl api, but did not have that data loaded.");
}
logError("Moment Timezone found " + intlName + " from the Intl api, but did not have that data loaded.");
} catch (e) {
// Intl unavailable, fall back to manual guessing.
}
Expand Down
16 changes: 16 additions & 0 deletions tests/moment-timezone/guess.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ exports.guess = {
test.done();
},

"When Intl is available, but timeZone is undefined, should return a guess without logging an error" : function (test) {
var oldError = console.error;
var errors = '';
console.error = function (message) {
errors += message;
};

mockIntlTimeZone(undefined);
mockTimezoneOffset(tz.zone('Europe/London'));
test.equal(tz.guess(true), 'Europe/London');
test.equal(errors, '');

console.error = oldError;
test.done();
},

"ensure each zone is represented" : function (test) {
var names = tz.names();
var zone, i;
Expand Down