Algorithm: how to check intersections of recurring events definitions?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 05:42:55

Since the period for the 1st recurrence is 14 days, parity (odd or even) of the day will only change when the month ends in an odd number: Jan, leap Feb, Mar, May, Jul, Aug, Oct, Dec. During a month it will not change.

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

  • 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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!