def _timestamp_parse(ts: ConvertableTimestamp) -> datetime:
"""
Takes something representing a timestamp and
returns a timestamp in the representation we want.
"""
if isinstance(ts, str):
ts = iso8601.parse_date(ts)
# Set resolution to milliseconds instead of microseconds
# (Fixes incompability with software based on unix time, for example mongodb)
ts = ts.replace(microsecond=int(ts.microsecond / 1000) * 1000)
# Add timezone if not set
if not ts.tzinfo:
# Needed? All timestamps should be iso8601 so ought to always contain timezone.
# Yes, because it is optional in iso8601
logger.warning("timestamp without timezone found, using UTC: {}".format(ts))
ts = ts.replace(tzinfo=timezone.utc)
return ts
评论列表
文章目录