Skip to content

Commit

Permalink
Adjustments to the 'last friday' command
Browse files Browse the repository at this point in the history
Fix missing import, add friday to accepted keywords
Remove the next Friday (does not make sense)
Document rather a whole example
  • Loading branch information
psss committed Oct 1, 2019
1 parent 5b38e48 commit 06bae06
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.rst
Expand Up @@ -41,10 +41,11 @@ Gather all stats for current week::

did

Show me all stats for today/yesterday::
Show me all stats for today, yesterday, last Friday::

did today
did yesterday
did last friday

Gather stats for the last month::

Expand Down
14 changes: 5 additions & 9 deletions did/base.py
Expand Up @@ -13,7 +13,7 @@
import StringIO
import xmlrpclib
import ConfigParser
from dateutil.relativedelta import MO as MONDAY
from dateutil.relativedelta import MO as MONDAY, FR as FRIDAY
from datetime import timedelta
from ConfigParser import NoOptionError, NoSectionError
from dateutil.relativedelta import relativedelta as delta
Expand Down Expand Up @@ -299,14 +299,10 @@ def period(argument):
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"
since.date += delta(weekday=FRIDAY(-1))
until.date += delta(weekday=FRIDAY(-1))
until.date += delta(days=1)
period = "the last friday"
elif "year" in argument:
if "last" in argument:
since, until = Date.last_year()
Expand Down
7 changes: 5 additions & 2 deletions did/cli.py
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] [friday|week|month|quarter|year] [options]")
usage="did [this|last] [week|month|quarter|year] [options]")
self._prepare_arguments(arguments)
self.opt = self.arg = None

Expand Down Expand Up @@ -148,7 +148,10 @@ def parse(self):

def check(self):
""" Perform additional check for given options """
keywords = "today yesterday this last week month quarter year".split()
keywords = [
'today', 'yesterday', 'friday',
'this', 'last',
'week', 'month', 'quarter', 'year']
for argument in self.arg:
if argument not in keywords:
raise did.base.OptionError(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_base.py
Expand Up @@ -75,8 +75,8 @@ def test_Date_period():
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"
assert unicode(until) == "2015-10-03"
assert period == "the last friday"
# This month
for argument in ["month", "this month"]:
since, until, period = Date.period(argument)
Expand Down

0 comments on commit 06bae06

Please sign in to comment.