Language agnostic 用于存储重复事件的数据结构?
我正在寻找一种用于存储重复事件的数据结构模式,但我提出的所有方法都会导致大量的特殊情况处理或用户输入,并且数据检索过于复杂。(我有一种明显的感觉,我对问题领域的理解还不够透彻,无法做到这一点。) 如何存储Outlook样式的定期事件Language agnostic 用于存储重复事件的数据结构?,language-agnostic,design-patterns,data-structures,Language Agnostic,Design Patterns,Data Structures,我正在寻找一种用于存储重复事件的数据结构模式,但我提出的所有方法都会导致大量的特殊情况处理或用户输入,并且数据检索过于复杂。(我有一种明显的感觉,我对问题领域的理解还不够透彻,无法做到这一点。) 如何存储Outlook样式的定期事件 每天早上8点 每个月的第一个星期二 三年内每年12月1日 一周内每两小时一次 有各种各样的文章描述了这个用例的数据结构和算法。此外,您还可以看到和(Java)或(.NET)的开源实现的代码或说明 这就是这样一篇论文 例如,cron存储这样的信息(*表示每个月,
- 每天早上8点
- 每个月的第一个星期二
- 三年内每年12月1日
- 一周内每两小时一次
*
表示每个月,因此month下的*
表示每个月)
——分钟(0-59)
|------小时(0-23)
||.------------月日(1-31)
|----月(1-12)或一月、二月、三月、四月。。。
|| | |------一周中的第几天(0-6)(星期日=0或7)或星期日、星期一、星期二、星期三、星期四、星期五、星期六
| | | | |
* * * * *
有几个特殊的条目,其中大部分只是快捷方式,
可以使用它来代替指定完整的cron条目:
条目描述相当于
@重新启动在启动时运行一次。没有一个
@每年运行一次0 0 1 1*
@每年(与@yearly相同)0 0 1 1*
@每月运行一次0 0 1**
@每周运行一次0**0
@每天运行一次0 0***
@午夜(与@daily相同)0***
@每小时运行一次0***
活动:
起始日期
结束日期(根据发生次数的变化计算)
发生次数(根据结束日期的变化计算)
频率,例如1/2小时、1/月、1/天等。。。。
校正功能,例如第一个星期二、上个星期天。。。
布尔森(日)
下一次策展日期(日期)
支持标准iCalendar事件类型 IETF在创建Internet日历和调度核心对象规范时考虑到了这一点,该规范被称为iCalendar 该规范包括事件重复 此外,您的数据库还可以与其他iCalendar兼容的数据源(如谷歌和苹果日历)共享数据 这是我的看法——如果我遗漏了什么,请告诉我: 根据Outlook定期选项,您有一个包含常规必需字段的表:
FieldName DataType Sample Data
ID int primary key
EventID int foreign key (to EventID from Event Table)
StartTime DateTime 8:00 AM
EndTime DateTime 8:30 AM
Duration int 30 (minutes)
StartDate DateTime 01/25/2014
EndBy DateTime 01/25/2024
NoEndDate bit False
NumOccurrences int 10
RecurrenceType int ****See below for instructions on how to use these last 6 fields
Int1 int
Int2 int
Int3 int
String1 nvarchar(50)
IntYears int
这就是魔法发生的地方。此逻辑只需要4个整数和一个字符串
The month of year (1 = Jan, 12 = Dec),
The day of the month (1 = the 1st, 31 = 31st),
Day of the week (0 = Sunday, 1=Monday, 6= Saturday),
Week of the month (1 = first, 4 = forth, 5 = last),
Yearly reocurrence ( 1=1,2=2)
When multiple days can be selected I use a comma delimited string (1,3,5 = Monday, Wed, Friday)
我按3个整数在outlook约会定期计划程序中出现的顺序输入它们,这样可以节省额外的时间、逻辑和麻烦。
*如果打开outlook appt scheduler,操作起来会稍微简单一些:
(每日、每月和每年有2个选项,每周有一个选项):
拉取或保存重新发生的代码变得相当简单
if (RecurrenceType = 10 )
Every `int1` days
if (RecurrenceType = 11)
Every Weekday
if (RecurrenceType = 20)
Every `int1 weeks on
parse `string1` and populate checkboxes for Mon, Tues, ...
if (RecurrenceType = 30)
`int1 day of every `int2` month
etc...
我希望我解释得足够透彻。如果有什么不清楚或不起作用,请告诉我。我正在为当前的应用程序构建此应用程序。谢谢大家。嘿!回答得好!这给我留下了一个悬而未决的问题:是否有一种快速的方法来计算开始日期和结束日期之间的所有日期,而不必重复每个日期?
The month of year (1 = Jan, 12 = Dec),
The day of the month (1 = the 1st, 31 = 31st),
Day of the week (0 = Sunday, 1=Monday, 6= Saturday),
Week of the month (1 = first, 4 = forth, 5 = last),
Yearly reocurrence ( 1=1,2=2)
When multiple days can be selected I use a comma delimited string (1,3,5 = Monday, Wed, Friday)
The RecurrenceType field can be any of the 7 following choices
10 = Daily (Every `Int1` day(s) )
Every 4 day(s)
11 = Daily (Every Weekday) -- no variables needed
Every Weekday (MTWTF)
20 = Weekly (Recur every `Int1` week(s) on: `String1`
Recur every 3 week(s) on Monday, Wednesday, Friday
(`String1` will be a list of days selected (0=Sunday, 1=Monday, 2=Tuesday... 7=Saturday) so for (Mon, Wed, Fri) String1 would hold "1,3,5". You would parse this on the code side to pull the actual days.)
30 = Monthly (Day `Int1` of every `int2' month(s)
Day 28 of every 2 month(s)
31 = Monthly (The `Int1` `Int2` of every `Int3` month(s)
The forth Tuesday of every 1 month(s)
40 = Yearly (Recur every `intYears` year(s) On `Int1` `Int2`) --
Recur every 1 year(s) on Jan 28th
41 = Yearly (Recur every `intYears` year(s) on the `Int1` `Int2` of `Int3`) --
Recur every 1 year(s) on the forth Tuesday of January
if (RecurrenceType = 10 )
Every `int1` days
if (RecurrenceType = 11)
Every Weekday
if (RecurrenceType = 20)
Every `int1 weeks on
parse `string1` and populate checkboxes for Mon, Tues, ...
if (RecurrenceType = 30)
`int1 day of every `int2` month
etc...