检测重叠的复发性的时间段算法 [英] Algorithm to detect overlapping recurent time periods

查看:138
本文介绍了检测重叠的复发性的时间段算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测事件的colision取决于天复发的和时间表

I'm trying to detect event's colision depending of the days recurrency and the timetable.

一个版本比这个问题的Algorithm检测重叠的时期

A version more complex than this issue Algorithm to detect overlapping periods.

我的情况:
中的一个事件是从上午8时至下午1时所有的周二,thurday和周六,两个日期之间。

My case : The A event is from 8am to 1pm all the tuesday, thurday and saturday, between two dates.

b事件是从上午11时至下午所有的周二和thurday ,日期两者之间(事件A的型动物)

The B event is from 11am to 2pm all the tuesday and thurday, between two dates(differents of event A)

在这里,我红色两个事件之间的colisions。

Here, I putted in red the colisions between the two events.

我花小时试图写的算法,以检测是否存在至少一个在两个事件之间colision。

I spent hour trying to write an algorithm to detect if there at least one colision between the two event.

顺便说一句事件结束之日起(倾向)可以undeterminate。

By the way the date of end of an event (tend) can be undeterminate.

是否有一个现有的算法来管理呢?

Is there an existing algorithm to manage this?

推荐答案

找出哪一个先结束。如果A和B均为无限只需在将来的某个随机日期。

Figure out which one ends first. If both A and B are unlimited just pick some random date in the future.

我要假设你的活动每周重复(每周还有的同样的重复时间)。如果这不是真的具有最大repeting基础(年/月/等等)。

I'm going to assume that your events repeat on a weekly basis (every week there's the same recurring times). If that's not true replace week with the largest repeting basis (month/year/whatever).

您在第一步选择了日期之前采取的最后一个星期。生成所有发生的这一周(确保你做的所有检查的事件,因为这些事件可能会开始在这个周期重复之一。对于每一个事件,你应该有开始和结束的具体时间戳记。现在检查,如果这些重叠。如果至少他们中的一些做那么你有一个碰撞,如果没有,那么你是好。

Take the last week before the date you picked in the first step. Generate all the events that happen that week (make sure you do all the checks, since one of the events might start repeating in this period. For each event you should have a concrete timestamp for start and end. Now check if these overlap. If at least some of them do then you have a collision. If not then you're good.

这篇关于检测重叠的复发性的时间段算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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