python 中稳健且完整的扩展或 RRULE
使用 dateutil.rrulestr,我设法扩展一些重复,例如看起来像这样的重复:
DTSTART;TZID=Europe/Zurich:20100930T183000
DTEND;TZID=Europe/Zurich:20100930T193000
RRULE:FREQ=DAILY;UNTIL=20101005T163000Z
BEGIN:VTIMEZONE
...
使用例如:
my_rrule.between(datetime.datetime(2010, 10, 2, 11, 00, tzinfo=pytz.utc),
datetime.datetime(2010, 10, 9, 11, 00, tzinfo=pytz.utc)))
但是,这只给我事件的开始日期时间,而不是结束日期时间。 有没有办法也获得结束时间? (比我自己计算开始结束增量并将其应用于每个开始时间更干净)。
此外,某些重复可以针对全天事件,并采用以下形式:
DTSTART;VALUE=DATE:20120225
DTEND;VALUE=DATE:20120226
RRULE:FREQ=WEEKLY;BYDAY=SA
BEGIN:VTIMEZONE
...
如果我尝试使用相同的 Between() 调用来扩展此重复,我会收到错误:
TypeError: can't compare offset-naive and offset-aware datetimes
是否有一些查询适用于任何类型的重复(理想情况下返回日期或日期时间值,具体取决于情况)?
Using dateutil.rrulestr, I manage to expand some recurrences, for example one that looks like:
DTSTART;TZID=Europe/Zurich:20100930T183000
DTEND;TZID=Europe/Zurich:20100930T193000
RRULE:FREQ=DAILY;UNTIL=20101005T163000Z
BEGIN:VTIMEZONE
...
using for example:
my_rrule.between(datetime.datetime(2010, 10, 2, 11, 00, tzinfo=pytz.utc),
datetime.datetime(2010, 10, 9, 11, 00, tzinfo=pytz.utc)))
However, this gives me only the start datetimes for the events, not the end datetimes.
Is there a way to get the end times too ? (cleaner than computing the start-end delta myself and applying it to every start time).
Also, some recurrences can be for all-day events and be in the form:
DTSTART;VALUE=DATE:20120225
DTEND;VALUE=DATE:20120226
RRULE:FREQ=WEEKLY;BYDAY=SA
BEGIN:VTIMEZONE
...
If I try to expand this one with the same between() call, I get an error:
TypeError: can't compare offset-naive and offset-aware datetimes
Is there some query that would work for any kind of recurrence (ideally returning date or datetime values, depending on the case) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dateutil.rrule
和朋友们没有持续时间的概念:他们正在重复时间瞬间的规则。我的解决方案是用自定义类替换 rruleset,该类也接受持续时间(或提供默认持续时间)。
然后,我可以生成事件,并附加每个事件的持续时间,以确定间隔。
dateutil.rrule
and friends have no concept of durations: they are repeating rules of instants in time.My solution was to replace
rruleset
with a custom class, that also accepts a duration (or provides a default one).Then, I can generate occurrences, and tack onto each occurrence it's duration, to determine the interval.