parser.add_option('-b', '--bare', dest='bare', action='store_true',
help='show histogram only', default=False)
parser.add_option('-W', '--isoweek', dest='isoweek',
- help='only show ISO [YYYY-]WK', default=None)
+ help='show ISO week range [YYYY-]WK[..[YYYY-]WK]', default=None)
parser.add_option('-f', '--field-sep', dest='sep', type='str',
help='field separator', metavar='f', default='')
parser.add_option('-i', '--ignore-case', dest='ignore_case', action='store_true',
startdate = enddate + dt.timedelta(opt.days)
if opt.isoweek:
- yw = opt.isoweek.split('-')
- if len(yw) == 1:
- year = dt.datetime.now().year
- week = int(yw[0])
- if len(yw) > 1:
- year = int(yw[0])
- week = int(yw[1])
+ # any number of periods denote a range of weeks
+ wrange = opt.isoweek.replace('.', ' ').split()
+ # may be one or two items
+ # if only one list item, then the second needs to be a copy of the first
+ wrange.append(wrange[0])
+
+ def wstr_to_date(wstr):
+ *year, week = wstr.split('-')
+
+ if year:
+ year = int(year[0])
+ else:
+ year = dt.datetime.now().year
+
+ week = int(week)
+ return (year, week)
+
+ year, week = wstr_to_date(wrange[0])
startdate = iso_to_gregorian(year, week, 1)
+
+ year, week = wstr_to_date(wrange[1])
enddate = iso_to_gregorian(year, week, 7)