dateutil/dateutil

Add variant or modify the MLK Day documentation exercise

Open

#775 创建于 2018年6月20日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)Python (2,189 star) (470 fork)batch import
docs exercisesdocumentationenhancementhelp wantedlow-difficulty

描述

Currently the MLK Day documentation exercise can be solved using the following RRULE:

(Hidden for those who don't want to see the issue)

from rrule import rrule, YEARLY, MO
from datetime import datetime

MLK_DAY = rrule(YEARLY, byweekday=(MO(3)),
           dtstart=datetime(1986, 1, 1))

This takes advantage of the fact that a YEARLY rule will just add 1 year to the original DTSTART before applying the by rules. This is a valid answer to the question, but a somewhat more precise answer that does not rely on dtstart having a specific value is:

from dateutil import rrule
from datetime import datetime

MLK_DAY = rrule.rrule(
    dtstart=datetime(1986, 1, 20),      # First celebration
    freq=rrule.YEARLY,                  # Occurs once per year
    bymonth=1,                          # In January
    byweekday=rrule.MO(+3),             # On the 3rd Monday
)

The problem should either be reworded so that the second answer is the only viable one, or we can create a "bonus challenge" that requires the second answer.

For example, the bonus challenge can fix dtstart at the day the bill was signed into law (1983-11-02), or we can say, "As a bonus, make sure that your RRULE still works when dtstart is replaced with an arbitrary datetime".

贡献者指南