From b180d97e4a79768a9ce703e12b4cbb77f466e6bb Mon Sep 17 00:00:00 2001 From: kitatek <30858833+kitatek@users.noreply.github.com> Date: Mon, 28 Dec 2020 14:31:18 +0800 Subject: [PATCH] Add day as a new time unit option to the existing minute and hours. --- ti/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ti/__init__.py b/ti/__init__.py index 89f00bf..b620a26 100755 --- a/ti/__init__.py +++ b/ti/__init__.py @@ -355,6 +355,12 @@ def parse_engtime(timestr): n = match.group(1) hours = 1 if n in ['a', 'an'] else int(n) return now - timedelta(hours=hours) + + match = re.match(r'(\d+|a) \s* (ds?|days?) \s+ ago $', timestr, re.X) + if match is not None: + n = match.group(1) + days = 1 if n in ['a'] else int(n) + return now - timedelta(hours=24*days) raise BadTime("Don't understand the time %r" % (timestr,))