rrule 月份日期超限 BUG
使用rrule时发现,如果给定一个并不是每月都有的日期作为起始时间,如31号,这个模块就会工作不正常,不按预期输出
官方解释:
http://dateutil.readthedocs.io/en/stable/_modules/dateutil/rrule.html
Per RFC section 3.3.10, recurrence instances falling on invalid dates and times are ignored rather than coerced:
Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day where the local time is moved forward by an hour at 1:00 AM).
Such recurrence instances MUST be ignored and MUST NOT be counted as part of the recurrence set.
This can lead to possibly surprising behavior when, for example, the start date occurs at the end of the month:
>>> from dateutil.rrule import rrule, MONTHLY
>>> from datetime import datetime
>>> start_date = datetime(2014, 12, 31)
>>> list(rrule(freq=MONTHLY, count=4, dtstart=start_date))
[datetime.datetime(2014, 12, 31, 0, 0),
datetime.datetime(2015, 1, 31, 0, 0),
datetime.datetime(2015, 3, 31, 0, 0),
datetime.datetime(2015, 5, 31, 0, 0)]
作者:Chihwei_hsu
来源:http://chihweihsu.com
Github:https://github.com/HsuChihwei

本文探讨了在使用rrule模块处理特定日期(如每月31日)时出现的一个Bug。当起始日期位于月末时,该模块可能无法正确地递归生成后续日期。官方文档指出,根据RFC标准,对于无效日期的实例应当被忽略。
8万+





