diff options
| author | 2019-11-27 15:06:47 +0700 | |
|---|---|---|
| committer | 2019-11-27 15:06:47 +0700 | |
| commit | 44f5ae308f69aa1e3349e1a350590e58302076cb (patch) | |
| tree | 97717ff9c3db0020159901506ef9dac1561004f2 | |
| parent | Added test for `get_duration_from_expiry()` (diff) | |
Updated `bot.utils.time.get_duration_from_expiry()` to accept an optional `date_from` ( for pytest and more control over the behaviour )
| -rw-r--r-- | bot/utils/time.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/bot/utils/time.py b/bot/utils/time.py index fc003f9e2..533b7ef83 100644 --- a/bot/utils/time.py +++ b/bot/utils/time.py @@ -147,7 +147,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) -> str: +def get_duration_from_expiry(expiry: str, date_from: datetime = None) -> str: """ Get the duration between datetime.utcnow() and an expiry, in human readable format. @@ -160,6 +160,6 @@ def get_duration_from_expiry(expiry: str) -> str: :param expiry: A string. """ - date_from = datetime.datetime.utcnow() + date_from = date_from or datetime.datetime.utcnow() date_to = dateutil.parser.isoparse(expiry).replace(tzinfo=None) return get_duration(date_from, date_to) |