Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last friday command #197

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions did/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ def period(argument):
until = Date("yesterday")
until.date += delta(days=1)
period = "yesterday"
elif "friday" in argument:
since = Date("today")
until = Date("today")
if "last" in argument:
since.date += delta(weekday=FR)
until.date += delta(weekday=FR)
period = "last friday"
else:
since.date += delta(weekday=FR(-1))
until.date += delta(weekday=FR(-1))
period = "next friday"
elif "year" in argument:
if "last" in argument:
since, until = Date.last_year()
Expand Down
2 changes: 1 addition & 1 deletion did/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Options(object):
def __init__(self, arguments=None):
""" Prepare the parser. """
self.parser = argparse.ArgumentParser(
usage="did [this|last] [week|month|quarter|year] [options]")
usage="did [this|last] [friday|week|month|quarter|year] [options]")
self._prepare_arguments(arguments)
self.opt = self.arg = None

Expand Down
6 changes: 6 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def test_Date_period():
assert unicode(since) == "2015-09-21"
assert unicode(until) == "2015-09-28"
assert period == "the week 39"
# Last Friday
for argument in ["last friday"]:
since, until, period = Date.period(argument)
assert unicode(since) == "2015-10-02"
assert unicode(until) == "2015-10-02"
assert period == "last friday"
# This month
for argument in ["month", "this month"]:
since, until, period = Date.period(argument)
Expand Down