aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2021-05-01 15:58:35 +0200
committerWolfgang Müller2021-05-01 17:41:47 +0200
commitc4f5dbab6e377fe7ee6040c3d5038157b58db621 (patch)
treeb1e924a43b2a362a3e62d2d3cfd8eb6c845d0564
parent60c6ffc224cca6bedfccfe2476d9e7294e6d7253 (diff)
downloadquarg-c4f5dbab6e377fe7ee6040c3d5038157b58db621.tar.gz
actions: Allow specifying a unit suffix for --around
Up until now it was only possible to give --around a range specified in hours. Since most discussions on IRC tend not to last for multiple hours, and one may only be interested in a few minutes of logs, this commit adds the ability to specify a unit suffix that takes either 'm' for minutes or 'h' for hours. If it is missing, 'h' is assumed.
Diffstat (limited to '')
-rw-r--r--quarg/actions.py18
-rw-r--r--quarg/main.py2
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')