|
@@ -2,6 +2,8 @@ import os
|
|
|
import time
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
+from ..constants import ISO_FORMAT, ISO_FORMAT_NO_USECS
|
|
|
+
|
|
|
|
|
|
def to_localtime(ts):
|
|
|
"""Convert datetime object from UTC to local time zone"""
|
|
@@ -10,10 +12,8 @@ def to_localtime(ts):
|
|
|
|
|
|
def parse_timestamp(timestamp):
|
|
|
"""Parse a ISO 8601 timestamp string"""
|
|
|
- if '.' in timestamp: # microseconds might not be present
|
|
|
- return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f').replace(tzinfo=timezone.utc)
|
|
|
- else:
|
|
|
- return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc)
|
|
|
+ fmt = ISO_FORMAT if '.' in timestamp else ISO_FORMAT_NO_USECS
|
|
|
+ return datetime.strptime(timestamp, fmt).replace(tzinfo=timezone.utc)
|
|
|
|
|
|
|
|
|
def timestamp(s):
|
|
@@ -98,7 +98,7 @@ def isoformat_time(ts: datetime):
|
|
|
Format *ts* according to ISO 8601.
|
|
|
"""
|
|
|
# note: first make all datetime objects tz aware before adding %z here.
|
|
|
- return ts.strftime('%Y-%m-%dT%H:%M:%S.%f')
|
|
|
+ return ts.strftime(ISO_FORMAT)
|
|
|
|
|
|
|
|
|
def format_timedelta(td):
|