Moment Timezone - detecting if the given time is ambiguous
1 answer
I think something like this will work:
function hasAmbiguousWallTime(m) {
var t = [60, -60, 30, -30];
var a = t.map(function(x) { return moment(m).add(x, 'm').format('HH:mm'); });
return a.indexOf(m.format('HH:mm')) > -1;
}
Examples:
hasAmbiguousWallTime(moment.tz("2011-11-06 01:00", "America/Chicago")) // true
hasAmbiguousWallTime(moment.tz("2011-11-06 00:00", "America/Chicago")) // false
Note that this may be unfortunate for transitions that do not change in 30 or 60 minutes in offset that have occurred historically. A better implementation would check for known jump points in the timezone data, or check for a locally derived moment. However, the above is sufficient for most modern applications.
0
source to share