diff --git a/flent/util.py b/flent/util.py index 51fcb893..17e25fc3 100644 --- a/flent/util.py +++ b/flent/util.py @@ -37,9 +37,14 @@ from copy import copy from calendar import timegm -from datetime import datetime, timedelta, UTC +from datetime import datetime, timedelta from math import log10, exp, sqrt +try: + from datetime import UTC +except ImportError: + UTC = None + from flent.loggers import get_logger MULTIHOST_SEP = '//' @@ -68,9 +73,13 @@ def classname(s, suffix=''): return uscore_to_camel(s) + suffix def utcnow(): + if UTC is None: + return datetime.utcnow() return datetime.now(UTC).replace(tzinfo=None) def utcfromtimestamp(ts): + if UTC is None: + return datetime.utcfromtimestamp(ts) return datetime.fromtimestamp(ts, UTC).replace(tzinfo=None) def format_date(dt, fmt="%Y-%m-%dT%H:%M:%S.%f", utc=False):