diff options
-rw-r--r-- | quarg/actions.py | 18 | ||||
-rw-r--r-- | quarg/main.py | 2 |
2 files changed, 16 insertions, 4 deletions
diff --git a/quarg/actions.py b/quarg/actions.py index 990327e..9361ac2 100644 --- a/quarg/actions.py +++ b/quarg/actions.py @@ -1,4 +1,5 @@ import argparse +import re from abc import ABCMeta, abstractmethod import dateutil.relativedelta @@ -49,14 +50,25 @@ class ParseAround(argparse.Action): if not rangespec: errx('Missing range for --around') + match = re.match(r'^(?P<range>\d+)(?P<unit>[hm])?$', rangespec) + + if not match: + errx(f'Invalid range for --around: \'{rangespec}\'') + + unit = match.group('unit') + try: - hour_range = int(rangespec) + time_range = int(match.group('range')) except ValueError as err: errx(f'Error when parsing range for --around: {err}') else: - datespec, hour_range = (aroundspec, 12) + datespec, time_range, unit = (aroundspec, 12, 'h') date = parse_isodate(datespec) - offset = dateutil.relativedelta.relativedelta(hours=hour_range) + if unit == 'm': + offset = dateutil.relativedelta.relativedelta(minutes=time_range) + else: + offset = dateutil.relativedelta.relativedelta(hours=time_range) + setattr(namespace, self.dest, (date - offset, date + offset)) diff --git a/quarg/main.py b/quarg/main.py index 083166c..82474b8 100644 --- a/quarg/main.py +++ b/quarg/main.py @@ -30,7 +30,7 @@ matchers.add_argument('-f', action=actions.ParseMessageFlag, dest='msgflag', hel date_matchers = cli.add_argument_group('matching message timestamps') date_matchers.add_argument('--after', action=actions.ParseDate, metavar='DATE', help='sent after this date') date_matchers.add_argument('--before', action=actions.ParseDate, metavar='DATE', help='sent before this date') -date_matchers.add_argument('--around', action=actions.ParseAround, metavar='DATE[/RANGE]', help='sent RANGE hours before or after this date') +date_matchers.add_argument('--around', action=actions.ParseAround, metavar='DATE[/RANGE]', help='sent RANGE hours/minutes before or after this date') joined_group = matchers.add_mutually_exclusive_group() joined_group.add_argument('--joined', default=None, action='store_true', dest='joined', help='match buffers which are currently joined') |