时区时区-检测给定时间是否模棱两可 [英] Moment Timezone - Detect if given time is ambiguous

查看:83
本文介绍了时区时区-检测给定时间是否模棱两可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

momentjs中是否有一种方法可以检查某个纪元是否模棱两可?

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

America/Chicago区域中,2011-11-06 00:00并不模糊,但2011-11-06 01:00可以是中央夏令时( CDT )或节省时间( CST ). /p>

In America/Chicago zone, 2011-11-06 00:00 is not ambiguous but 2011-11-06 01:00 can be either Central Daylight Time (CDT) or Savings Time (CST).

推荐答案

我认为这样会起作用:

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;
}

示例:

hasAmbiguousWallTime(moment.tz("2011-11-06 01:00", "America/Chicago")) // true
hasAmbiguousWallTime(moment.tz("2011-11-06 00:00", "America/Chicago")) // false

请注意,如果偏移量没有改变30或60分钟(过去已发生),则此操作可能会失败.更好的实现方式是测试弯矩-时区数据中的已知过渡点,或针对本地派生的弯矩进行扫描.也就是说,以上对于大多数现代用法已经足够.

Note that this might fail for transitions that are not either 30 or 60 minutes change in offset, which have occurred historically. A better implementation would test the known transition points in the moment-timezone data, or scan for them against a locally derived moment. That said, the above is sufficient for most modern usage.

这篇关于时区时区-检测给定时间是否模棱两可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆