描述
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".