aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2018-06-07 20:09:47 +0100
committerPaul Ganssle <paul@ganssle.io>2018-06-08 07:26:52 +0100
commit404af91dce1e44879ee38dc7e3038b0f85f7afa6 (patch)
tree73362e84d928c5cd140158480bb5c1bf92c62554 /docs
parentcaa60adc56c81c4af071191881b04cf2638b0308 (diff)
downloaddateutil-404af91dce1e44879ee38dc7e3038b0f85f7afa6.tar.gz
Add Martin Luther King Day exercise
Diffstat (limited to 'docs')
-rw-r--r--docs/exercises/index.rst58
1 files changed, 58 insertions, 0 deletions
diff --git a/docs/exercises/index.rst b/docs/exercises/index.rst
index 654b665..d43337d 100644
--- a/docs/exercises/index.rst
+++ b/docs/exercises/index.rst
@@ -10,3 +10,61 @@ If you are interested in helping improve the documentation of ``dateutil``, it i
:backlinks: top
:local:
+
+Martin Luther King Day
+--------------------------------
+
+
+ `Martin Luther King, Jr Day <https://en.wikipedia.org/wiki/Martin_Luther_King_Jr._Day>`_ is a US holiday that occurs every year on the third Monday in January?
+
+ How would you generate a `recurrence rule <../rrule.html>`_ that generates Martin Luther King Day, starting from its first observance in 1986?
+
+
+**Test Script**
+
+To solve this exercise, copy-paste this script into a document, change anything between the ``--- YOUR CODE ---`` comment blocks.
+
+.. raw:: html
+
+ <details>
+
+.. code-block:: python3
+
+ # ------- YOUR CODE -------------#
+ from dateutil import rrule
+
+ MLK_DAY = <<YOUR CODE HERE>>
+
+ # -------------------------------#
+
+ 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!')
+
+
+.. raw:: html
+
+ </details>
+
+