Switch to UTC timestamps, output in local time
This commit is contained in:
@@ -27,11 +27,18 @@ __all__ = [
|
||||
|
||||
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z"
|
||||
|
||||
|
||||
def datetime_str(dt, utc=False):
|
||||
if not isinstance(dt, datetime.datetime):
|
||||
return "Never"
|
||||
|
||||
aware_dt = dt.replace(tzinfo=datetime.UTC) if not dt.tzinfo else dt
|
||||
|
||||
if utc:
|
||||
return timestamp.strftime(DATETIME_FORMAT)
|
||||
return aware_dt.strftime(DATETIME_FORMAT)
|
||||
else:
|
||||
return timestamp.astimezone().strftime(DATETIME_FORMAT)
|
||||
return aware_dt.astimezone().strftime(DATETIME_FORMAT)
|
||||
|
||||
|
||||
def utc_now():
|
||||
return datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
|
||||
|
||||
Reference in New Issue
Block a user