gpt4 book ai didi

javascript - 使用momentjs检查这个时间范围是否与其他时间范围冲突

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:00:23 25 4
gpt4 key购买 nike

场景一

Time range 1 : 2016-12-06 11:00 to 2016-12-06 12:00
Time range 2 : 2016-12-06 10:00 to 2016-12-06 13:00
time range 1 is completely conflict with time range 2 and vice versa

场景 2

Time range 1 : 2016-12-06 11:00 to 2016-12-06 12:00
Time range 2 : 2016-12-06 11:00 to 2016-12-06 14:00
time range 1 is partial conflict with time range 2 and vice versa

场景 3

Time range 1 : 2016-12-06 11:00 to 2016-12-06 12:00
Time range 2 : 2016-12-06 09:00 to 2016-12-06 12:00
time range 1 is partial conflict with time range 2 and vice versa

如何使用 momentjs 完成上述场景?我尝试了 isBetween 函数,但无法正常工作。

最佳答案

我认为moment-range是你要找的。使用它的overlapscontains 功能来制作它。您可以从 cdnjs servers 链接到时刻范围.

var date1 = [moment("2016-12-06 11:00"), moment("2016-12-06 12:00")];
var date2 = [moment("2016-12-06 10:00"), moment("2016-12-06 13:00")];

var range = moment.range(date1);
var range2 = moment.range(date2);

// has overlapping
if(range.overlaps(range2)) {
if((range2.contains(range, true) || range.contains(range2, true)) && !date1[0].isSame(date2[0]))
alert("time range 1 is completely conflict with time range 2 and vice versa");
else
alert("time range 1 is partially conflict with time range 2 and vice versa");
}

关于javascript - 使用momentjs检查这个时间范围是否与其他时间范围冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40970369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com