Data structure for storing recurring events?

后端 未结 4 727
攒了一身酷
攒了一身酷 2020-12-07 10:47

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 an

4条回答
  •  孤城傲影
    2020-12-07 11:11

    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 * * * *
    
    

提交回复
热议问题