diff options
author | 2019-11-27 17:16:06 +0700 | |
---|---|---|
committer | 2019-11-27 17:16:06 +0700 | |
commit | f5f92b76fb536beedbbfacd97f2977ed1c2c8606 (patch) | |
tree | 5863d5456a4948b3a5e6b210f895282bc1514095 | |
parent | Added duration until expiration for infraction searching. (diff) |
Changed `get_duration_from_expiry()` to return the `time (duration)` or a `''`
-rw-r--r-- | bot/utils/time.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/bot/utils/time.py b/bot/utils/time.py index 873de21f0..311a0a576 100644 --- a/bot/utils/time.py +++ b/bot/utils/time.py @@ -148,7 +148,7 @@ def get_duration(date_from: datetime.datetime, date_to: datetime.datetime) -> st return ', '.join(results[::-1][:2]) -def get_duration_from_expiry(expiry: str, date_from: datetime = None) -> str: +def get_duration_from_expiry(expiry: str = None, date_from: datetime = None) -> Optional[str]: """ Get the duration between datetime.utcnow() and an expiry, in human readable format. @@ -161,6 +161,15 @@ def get_duration_from_expiry(expiry: str, date_from: datetime = None) -> str: :param expiry: A string. """ + if not expiry: + return None + date_from = date_from or datetime.datetime.utcnow() date_to = dateutil.parser.isoparse(expiry).replace(tzinfo=None) - return get_duration(date_from, date_to) + + expiry_formatted = format_infraction(expiry) + + duration = get_duration(date_from, date_to) + duration_formatted = f" ({duration})" if duration else '' + + return f"{expiry_formatted}{duration_formatted}" |