From 1674ef325b364056e08dd0be5f38c275956cf475 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 30 Jan 2020 14:58:32 +0000 Subject: [PATCH] add utils.datetime.seconds_since(); compare utcnow to datetime --- src/utils/datetime.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/datetime.py b/src/utils/datetime.py index 0a916dbd..650893d1 100644 --- a/src/utils/datetime.py +++ b/src/utils/datetime.py @@ -43,6 +43,9 @@ def datetime_human(dt: _datetime.datetime, timespec: TimeSpec=TimeSpec.NORMAL): def date_human(dt: _datetime.datetime, timespec: TimeSpec=TimeSpec.NORMAL): return _datetime.datetime.strftime(dt, DATE_HUMAN) +def seconds_since(dt: _datetime.datetime) -> float: + return (utcnow()-dt).total_seconds() + TIME_SECOND = 1 TIME_MINUTE = TIME_SECOND*60 TIME_HOUR = TIME_MINUTE*60