用于存储重复事件的数据结构? [英] Data structure for storing recurring events?

查看:114
本文介绍了用于存储重复事件的数据结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找用于存储循环事件的数据结构模式,但是我提出的一切将导致大量特殊情况处理或用户输入和数据检索过于复杂。 (我得到了明确的感觉,我不明白问题域足够好这样做。)



如何存储Outlook样式的循环事件? p>


  • 每天上午8点

  • 每月第一个星期二

  • 每12月1日三年

  • 每两个小时一周

  • ...


解决方案

有各种论文描述这种用例的数据结构和算法。此外,您还可以查看 crontab 的开源实现的代码或描述,以及 Quartz (Java)或 Quartz.NET (.NET)。



这是一张这样的论文



http:// portal。 acm.org/citation.cfm?id=359763.359801&coll=ACM&dl=ACM&CFID=63647367&CFTOKEN=55814330



例如, cron存储这样的信息( * 意味着每一个,所以一个 * 在月份下表示每个月)

 

.----------------分钟(0 - 59)
| .-------------小时(0 - 23)
| | .──月份(1 - 31)
| | | (1 - 12)OR jan,feb,mar,apr ...
| | | | 。星期几(0 - 6)(星期日= 0或7)或太阳,星期一,星期二,星期五,星期五, | | | |
* * * * *

有几个特殊条目,其中大部分只是快捷方式,可以使用
而不是指定完整的cron条目:

条目描述等价于
@reboot在启动时运行一次。无
@yearly每年运行一次0 0 1 1 *
@annually(与@yearly相同)0 0 1 1 *
@monthly每月运行一次0 0 1 * *
@weekly每周运行一次0 0 * * 0
@daily每天运行一次0 0 * * *
@midnight(和@daily相同)0 0 * * *
@每小时运行一次0 * * * *


I'm looking for a data structure pattern for storing recurring events, but everything I came up with would result in a high number of special case handling or user input and data retrieval are overly complex. (I get the distinct feeling, that I haven't understand the problem domain well enough to do this.)

How can I store Outlook-style recurring events?

  • Every day at 8am
  • Every first tuesday in a month
  • Every December 1st for three years
  • Every two hours for a week
  • ...

解决方案

There are various papers describing data structures and algorithms for this use case. In addition you can see the code or descriptions of open source implementation of crontab and of Quartz (Java) or Quartz.NET (.NET).

This is one such paper

http://portal.acm.org/citation.cfm?id=359763.359801&coll=ACM&dl=ACM&CFID=63647367&CFTOKEN=55814330

For example, cron stores the information like this (* means every, so a * under month means every month)


.---------------- minute (0 - 59) 
|  .------------- hour (0 - 23)
|  |  .---------- day of month (1 - 31)
|  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
|  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat 
|  |  |  |  |
*  *  *  *  * 

There are several special entries, most of which are just shortcuts, 
that can be used instead of specifying the full cron entry:

Entry      Description                 Equivalent To
@reboot    Run once, at startup.       None
@yearly    Run once a year             0 0 1 1 *
@annually  (same as @yearly)           0 0 1 1 *
@monthly   Run once a month            0 0 1 * *
@weekly    Run once a week             0 0 * * 0
@daily     Run once a day              0 0 * * *
@midnight  (same as @daily)            0 0 * * *
@hourly    Run once an hour            0 * * * *

这篇关于用于存储重复事件的数据结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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