-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #774 from pganssle/add_mlk_day_solution
Add solution to Martin Luther King Day exercise
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:orphan: | ||
|
||
Martin Luther King Day: Solution | ||
================================ | ||
|
||
Presented here is a solution to the :ref:`Martin Luther King Day exercises <mlk-day-exercise>`. | ||
|
||
|
||
.. include:: mlk_day_rrule_solution.py | ||
:code: python3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# ------- YOUR CODE -------------# | ||
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 | ||
) | ||
|
||
# -------------------------------# | ||
|
||
from datetime import datetime | ||
|
||
MLK_TEST_CASES = [ | ||
((datetime(1970, 1, 1), datetime(1980, 1, 1)), | ||
[]), | ||
((datetime(1980, 1, 1), datetime(1989, 1, 1)), | ||
[datetime(1986, 1, 20), | ||
datetime(1987, 1, 19), | ||
datetime(1988, 1, 18)]), | ||
((datetime(2017, 2, 1), datetime(2022, 2, 1)), | ||
[datetime(2018, 1, 15, 0, 0), | ||
datetime(2019, 1, 21, 0, 0), | ||
datetime(2020, 1, 20, 0, 0), | ||
datetime(2021, 1, 18, 0, 0), | ||
datetime(2022, 1, 17, 0, 0)] | ||
), | ||
] | ||
|
||
|
||
def test_mlk_day(): | ||
for (between_args, expected) in MLK_TEST_CASES: | ||
assert MLK_DAY.between(*between_args) == expected | ||
|
||
|
||
if __name__ == "__main__": | ||
test_mlk_day() | ||
print('Success!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters