Repository: psss/did

Issue:
`did last friday` - only friday supported?
The `last friday` command example in the README is neat but unless I'm missing something only `friday` seems to be supported as a argument?

```console
% did last friday
Status report for the last friday (2023-05-12 to 2023-05-12).
... report here
```

```console
% did last thursday
 ERROR  Invalid argument: 'thursday'
```

```console
% did last wednesday
 ERROR  Invalid argument: 'wednesday'
```

```console
% did last tuesday  
 ERROR  Invalid argument: 'tuesday'
```

...etc

It'd be really nice any day could be used.

Discussion:
@psss: Nice idea, sounds good! And should be fairly easy to implement:

https://github.com/psss/did/blob/9ceed73b7f7dcb03b30f267eca70a820b6257dcf/did/base.py#L332-L338

Pull request is welcome :)

Solution patch:
diff --git a/README.rst b/README.rst
index 8eaf26b..e726d8b 100644
--- a/README.rst
+++ b/README.rst
@@ -31,7 +31,7 @@ Synopsis
 
 Usage is straightforward::
 
-    did [this|last] [week|month|quarter|year] [opts]
+    did [this|last] [week|month|quarter|year|monday|..|sunday] [opts]
 
 
 Examples
diff --git a/did/base.py b/did/base.py
index 8cd8bad..1becb31 100644
--- a/did/base.py
+++ b/did/base.py
@@ -14,6 +14,11 @@ from datetime import timedelta
 
 from dateutil.relativedelta import FR as FRIDAY
 from dateutil.relativedelta import MO as MONDAY
+from dateutil.relativedelta import SA as SATURDAY
+from dateutil.relativedelta import SU as SUNDAY
+from dateutil.relativedelta import TH as THURSDAY
+from dateutil.relativedelta import TU as TUESDAY
+from dateutil.relativedelta import WE as WEDNESDAY
 from dateutil.relativedelta import relativedelta as delta
 
 from did import utils
@@ -329,13 +334,40 @@ class Date(object):
             until = Date("yesterday")
             until.date += delta(days=1)
             period = "yesterday"
-        elif "friday" in argument:
+        elif "monday" in argument or "tuesday" in argument or \
+             "wednesday" in argument or "thursday" in argument or \
+             "friday" in argument or "saturday" in argument or \
+             "sunday" in argument:
+            today = Date("today")
             since = Date("today")
-            until = Date("today")
-            since.date += delta(weekday=FRIDAY(-1))
-            until.date += delta(weekday=FRIDAY(-1))
-            until.date += delta(days=1)
-            period = "the last friday"
+            until = Date()
+            if "monday" in argument:
+                weekday = MONDAY(-1)
+                period = "the last monday"
+            elif "tuesday" in argument:
+                weekday = TUESDAY(-1)
+                period = "the last tuesday"
+            elif "wednesday" in argument:
+                weekday = WEDNESDAY(-1)
+                period = "the last wednesday"
+            elif "thursday" in argument:
+                weekday = THURSDAY(-1)
+                period = "the last thursday"
+            elif "friday" in argument:
+                weekday = FRIDAY(-1)
+                period = "the last friday"
+            elif "saturday" in argument:
+                weekday = SATURDAY(-1)
+                period = "the last saturday"
+            else:
+                weekday = SUNDAY(-1)
+                period = "the last sunday"
+            since.date += delta(weekday=weekday)
+            if since.date == today.date:
+                # technically last dayofweek is today, but we want
+                # the one week ago
+                since.date -= delta(days=7)
+            until.date = since.date + delta(days=1)
         elif "year" in argument:
             if "last" in argument:
                 since, until = Date.last_year()
diff --git a/did/cli.py b/did/cli.py
index 8c51acc..d7ca600 100644
--- a/did/cli.py
+++ b/did/cli.py
@@ -169,7 +169,8 @@ class Options(object):
     def check(self):
         """ Perform additional check for given options """
         keywords = [
-            'today', 'yesterday', 'friday',
+            'today', 'yesterday', 'monday', 'tuesday', 'wednesday', 'thursday',
+            'friday', 'saturday', 'sunday',
             'this', 'last',
             'week', 'month', 'quarter', 'year']
         for argument in self.arg:


Test patch:
diff --git a/tests/test_base.py b/tests/test_base.py
index ae5f031..ac757d9 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -73,6 +73,30 @@ def test_Date_period():
         assert str(since) == "2015-09-21"
         assert str(until) == "2015-09-28"
         assert period == "the week 39"
+    # Last Monday
+    for argument in ["last monday"]:
+        since, until, period = Date.period(argument)
+        assert str(since) == "2015-09-28"
+        assert str(until) == "2015-09-29"
+        assert period == "the last monday"
+    # Last Tuesday
+    for argument in ["last tuesday"]:
+        since, until, period = Date.period(argument)
+        assert str(since) == "2015-09-29"
+        assert str(until) == "2015-09-30"
+        assert period == "the last tuesday"
+    # Last Wednesday
+    for argument in ["last wednesday"]:
+        since, until, period = Date.period(argument)
+        assert str(since) == "2015-09-30"
+        assert str(until) == "2015-10-01"
+        assert period == "the last wednesday"
+    # Last Thursday
+    for argument in ["last thursday"]:
+        since, until, period = Date.period(argument)
+        assert str(since) == "2015-10-01"
+        assert str(until) == "2015-10-02"
+        assert period == "the last thursday"
     # Last Friday
     for argument in ["last friday"]:
         since, until, period = Date.period(argument)