Moment Timezone - detecting if the given time is ambiguous

Is there a way to check if an era is ambiguous or not in momentjs?

The zone is America/Chicago

2011-11-06 00:00

not ambiguous, but 2011-11-06 01:00

can be either central daytime (CDT) or save time (CST).

+2


source to share


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







All Articles