Skip to content

Commit

Permalink
Check that the timezone matches the utc offset to work around Intl AP…
Browse files Browse the repository at this point in the history
…I being unreliable. moment#517
  • Loading branch information
ccorcos committed Apr 24, 2019
1 parent c377ac8 commit 0738402
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions moment-timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,16 @@
if (intlName && intlName.length > 3) {
var name = names[normalizeName(intlName)];
if (name) {
return name;
// Sometimes the Intl API is unreliable and returns a time zone that is
// inconsistent with the actual time zone offset.
// https://github.com/moment/moment-timezone/issues/517
var zone = getZone(name);
if (zone) {
var currentOffset = (new Date()).getTimezoneOffset();
if (zone.offsets.indexOf(currentOffset) !== -1) {
return name;
}
}
}
logError("Moment Timezone found " + intlName + " from the Intl api, but did not have that data loaded.");
}
Expand Down Expand Up @@ -397,7 +406,6 @@
}

function getZone (name, caller) {

name = normalizeName(name);

var zone = zones[name];
Expand Down Expand Up @@ -598,7 +606,7 @@
fn.utc = resetZoneWrap(fn.utc);
fn.local = resetZoneWrap(fn.local);
fn.utcOffset = resetZoneWrap2(fn.utcOffset);

moment.tz.setDefault = function(name) {
if (major < 2 || (major === 2 && minor < 9)) {
logError('Moment Timezone setDefault() requires Moment.js >= 2.9.0. You are using Moment.js ' + moment.version + '.');
Expand Down

0 comments on commit 0738402

Please sign in to comment.