diff options
author | Paul Ganssle <paul@ganssle.io> | 2018-06-20 11:24:19 -0400 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2018-10-25 13:37:25 -0400 |
commit | 13ce77380ca745ada1a5252e264c97029facc075 (patch) | |
tree | 1b49f8e7b88447b69e7195d27b40f39a464b36d1 | |
parent | 937773a5974e0b8d56b0bd240d8af5364264c423 (diff) | |
download | dateutil-13ce77380ca745ada1a5252e264c97029facc075.tar.gz |
Add solution to Martin Luther King Day exercise
Currently this solution is not automatically tested, but was
manually tested using Python 3.6.5.
-rw-r--r-- | docs/exercises/index.rst | 3 | ||||
-rw-r--r-- | docs/exercises/solutions/mlk-day-rrule.rst | 48 |
2 files changed, 51 insertions, 0 deletions
diff --git a/docs/exercises/index.rst b/docs/exercises/index.rst index 85c7e0b..e5e5783 100644 --- a/docs/exercises/index.rst +++ b/docs/exercises/index.rst @@ -11,6 +11,8 @@ If you are interested in helping improve the documentation of ``dateutil``, it i :local: +.. _mlk-day-exercise: + Martin Luther King Day -------------------------------- @@ -66,6 +68,7 @@ To solve this exercise, copy-paste this script into a document, change anything </details> +A solution to this problem is provided :doc:`here <solutions/mlk-day-rrule>`. Next Monday meeting diff --git a/docs/exercises/solutions/mlk-day-rrule.rst b/docs/exercises/solutions/mlk-day-rrule.rst new file mode 100644 index 0000000..b8da806 --- /dev/null +++ b/docs/exercises/solutions/mlk-day-rrule.rst @@ -0,0 +1,48 @@ +:orphan: + +Martin Luther King Day: Solution +================================ + +Presented here is a solution to the :ref:`Martin Luther King Day exercises <mlk-day-exercise>`. + + +.. code-block:: python3 + + # ------- 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!') + |