算法:如何检查重复事件定义的交点? [英] Algorithm: how to check intersections of recurring events definitions?

查看:214
本文介绍了算法:如何检查重复事件定义的交点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在的问题是来自MS Outlook日历的行为。

The question comes from MS Outlook calendar behavior.

想象一下,我有两个经常性事件(从今天起):每一秒星期一和每奇日。有没有什么办法来检查算法路口和/或找到的第一个交叉日期没有每个日期暴力破解了吗?

Imagine I have two recurring events (starting from today): "each second Monday" and "every odd date". Is there any way to check intersections and/or find the first intersecting date algorithmically without brute-forcing over each date?

定义可以在CRON的符号或符号的iCal进行。我觉得没关系。

Definitions can be made in CRON's notations or ICal notation. I think it doesn't matter.

对于这种在公历有没有解决方案?

Are there any solutions for this in Gregorian calendar?

UPD :也很想知道MS Outlook日历如何处理这些事件。我的意思是如何发现前。今天有两个事件?我想应该也是技术确定具体的日期是否适合经​​常性的事件定义。

UPD: It is also interesting to know how MS Outlook Calendar handles these events. I mean how it discovers that ex. today has two events? I guess should be also technique for determination of whether concrete date suits recurring event definition.

形式上可以描述为两个函数算法:

Date:intersection(Event e1, Event e2)
boolean:contains(Date date, Event ev)

对于限制,我们可以从事件定义符号。您可以在Outlook中(或iCal中)看到的,你可以定义并不复杂的一种经常性的事件。

Regarding restrictions, we can go from event definition notation. You can see in outlook (or iCal), that you can define not that complex kind of recurring event.

推荐答案

如果你只关心什么时候从不同的复发事件发生在同一天,你可以:

If you are only concerned about when events from different recurrences occur on the same day you could:

  • ,建立一些任意天在最近的过去的1天。
  • 数的天事件,开始一天的
  • 在防爆preSS每次复发为;如果你的事件发生时,每周一和每周四再前preSS这是2复发有2天的开始。
  • 使用合适的模运算找到日子,从不同的复发事件发生碰撞。
  • Establish some arbitrary day in the recent past as day 1.
  • Express each recurrence as a 'number-of-days' between events and a start day; if your event occurs every Monday and every Thursday then express this as 2 recurrences with 2 start days.
  • Use appropriate modular arithmetic to find days when the events from different recurrences collide.

例如,如果复发每星期一和每一个第5天无论发生碰撞,第1天,他们将在下碰撞在第36,第71,第106,等天

Eg if recurrences 'every Monday' and every '5th day' both collide on day 1, they will next collide on the 36th, 71st, 106th, etc days

如果你想要更多的东西precise你需要测量不是在整个天,但在一天你有兴趣的任何部分。

If you want something more precise you would need to measure not in whole days but in whatever fraction of a day you are interested in.

这篇关于算法:如何检查重复事件定义的交点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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