如何让 iCalendar (RFC 2445) 每年重复一次并持续一段时间
我未能成功制定允许发生如下所示事件的规则:
每年重复一次,从四月的第一个星期日到五月的最后一天,发生在星期一、星期三和星期五,直到永远。
FREQ=YEARLY;BYMONTH=4;BYDAY=SU (给我每年重复的四月的第一个星期日)
和
FREQ=YEARLY;BYMONTH=5;BYMONTHDAY=-1 (给我五月的最后一天,每年重复)
但我不知道如何让该事件在周一、周三和周五的这些日期之间每年重复一次。
建议?
更新:评论没有足够的空间来回复克里斯的回答,因此我正在编辑问题以提供更多信息。
很不幸的是,不行。 我不知道这是否是我正在使用的 DDay.iCal 库,或者什么,但这也不起作用。 我发现开始日期不能是序数日期(第一个星期日等)..它必须是一个特定的日期,这使得它很难满足我的要求。 即使使用多个 RRULE,它似乎也不起作用:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//DDay.iCal//NONSGML ddaysoftware.com//EN
BEGIN:VEVENT
CREATED:20090717T033307Z
DTSTAMP:20090717T033307Z
DTSTART:20090101T000000
RRULE:FREQ=YEARLY;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=4,5
RRULE:FREQ=YEARLY;WKST=SU;BYDAY=1SU;BYMONTH=4
RRULE:FREQ=YEARLY;WKST=SU;BYMONTH=5;BYMONTHDAY=-1
SEQUENCE:0
UID:352ed9d4-04d0-4f06-a094-fab7165e5c74
END:VEVENT
END:VCALENDAR
表面上看起来很正确(我什至在 2009 年 1 月 1 日开始活动),但是当我开始测试某些日期是否有效时,我得到了不正确的结果。
例如,
4/1/2009 12:00:00 AM = True // Should be False
4/6/2009 12:00:00 AM = True
4/7/2009 12:00:00 AM = False
4/8/2009 12:00:00 AM = True
5/1/2009 12:00:00 AM = True
5/2/2009 12:00:00 AM = False
5/29/2009 12:00:00 AM = True
5/31/2009 12:00:00 AM = True // Should be False
6/1/2009 12:00:00 AM = False
我正在使用 Douglas Day 的 DDay.iCal软件,但我不认为这是该库中的错误。 我认为这可能是 iCalendar (RFC 2445) 的限制。
想法?
I have been unsuccessful in formulating a RRULE that would allow an event as shown below:
Repeats YEARLY, from first Sunday of April to last day of May, occuring on Monday, Wednesday and Friday, until forever.
FREQ=YEARLY;BYMONTH=4;BYDAY=SU (gives me the first Sunday of April repeating yearly)
and
FREQ=YEARLY;BYMONTH=5;BYMONTHDAY=-1 (gives me the last day of May repeating yearly)
But I can't figure out how to have the event repeat yearly between those dates for Monday, Wednesday and Friday.
Suggestions?
Update: Comments don't have enough space to respond to Chris' answer, so I am editing the question with further information.
Unfortunately, no. I don't know if it is the DDay.iCal library I'm using, or what, but that doesn't work either. I've found that the date start can't be an ordinal date (first Sunday, etc.)..it has to be a specific date, which makes it difficult for my requirements. Even using multiple RRULE's it doesn't seem to work:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//DDay.iCal//NONSGML ddaysoftware.com//EN
BEGIN:VEVENT
CREATED:20090717T033307Z
DTSTAMP:20090717T033307Z
DTSTART:20090101T000000
RRULE:FREQ=YEARLY;WKST=SU;BYDAY=MO,WE,FR;BYMONTH=4,5
RRULE:FREQ=YEARLY;WKST=SU;BYDAY=1SU;BYMONTH=4
RRULE:FREQ=YEARLY;WKST=SU;BYMONTH=5;BYMONTHDAY=-1
SEQUENCE:0
UID:352ed9d4-04d0-4f06-a094-fab7165e5c74
END:VEVENT
END:VCALENDAR
That looks right on the face (I'm even starting the event on 1/1/2009), but when I start testing whether certain days are valid, I get incorrect results.
For example,
4/1/2009 12:00:00 AM = True // Should be False
4/6/2009 12:00:00 AM = True
4/7/2009 12:00:00 AM = False
4/8/2009 12:00:00 AM = True
5/1/2009 12:00:00 AM = True
5/2/2009 12:00:00 AM = False
5/29/2009 12:00:00 AM = True
5/31/2009 12:00:00 AM = True // Should be False
6/1/2009 12:00:00 AM = False
I'm using Douglas Day's DDay.iCal software, but I don't think it is a bug in that library. I think this might be a limitation in iCalendar (RFC 2445).
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 BYMONTH 规则来指定您只希望在四月和五月出现:
这不会处理“四月第一个星期天”位,该位不在模式的 MWF 部分中。 我认为,如果您将此特定日期设置为 dtStart 日期,则第一次出现的情况将被涵盖(但当然,这不会在明年再次出现)。 否则,我认为您可能需要第二条规则:
这有帮助吗?
Try the BYMONTH rule to specify that you only want it in April and May:
This won't handle the "First Sunday of April" bit, which isn't in the MWF part of the pattern. I think this will be covered for the first occurrence if you set this specific date as your dtStart date (but of course, that won't recur for the next year by itself). Otherwise, I think you may need a second RRULE for that:
Does that help?
Todd,
使用上面的 3 个 RRULE 将产生结果的并集,而不是交集。 你是对的,RFC2445/5545 中没有一种非常优雅的方式。 但是,如果您能够在生成事件时以编程方式计算四月的第一个星期日,则以下方法应该有效:
此方法至少看起来更接近您想要实现的目标。
-道格
Todd,
Using the 3 RRULEs as you have above will produce a union of results, not an intersection. You're right that there isn't a very graceful way in RFC2445/5545. However, if you have the ability to programatically calculate the first Sunday in April while you generate the event, the following should work:
This method at least seems closer to what you were trying to achieve.
-Doug