Loading src/common/tools/timestamp/Converters.py +12 −3 Original line number Diff line number Diff line Loading @@ -13,14 +13,23 @@ # limitations under the License. import dateutil.parser import dateutil.parser, math from datetime import datetime, timezone def timestamp_datetime_to_float(dt_timestamp : datetime) -> int: return math.floor(dt_timestamp.timestamp()) def timestamp_datetime_to_int(dt_timestamp : datetime) -> int: return math.floor(timestamp_datetime_to_float(dt_timestamp)) def timestamp_string_to_float(str_timestamp : str) -> float: return datetime.timestamp(dateutil.parser.isoparse(str_timestamp)) return timestamp_datetime_to_float(dateutil.parser.isoparse(str_timestamp)) def timestamp_float_to_string(flt_timestamp : float) -> str: return datetime.utcfromtimestamp(flt_timestamp).isoformat() + 'Z' def timestamp_utcnow_to_datetime() -> datetime: return datetime.now(tz=timezone.utc) def timestamp_utcnow_to_float() -> float: return datetime.timestamp(datetime.now(tz=timezone.utc)) return timestamp_datetime_to_float(timestamp_utcnow_to_datetime()) Loading
src/common/tools/timestamp/Converters.py +12 −3 Original line number Diff line number Diff line Loading @@ -13,14 +13,23 @@ # limitations under the License. import dateutil.parser import dateutil.parser, math from datetime import datetime, timezone def timestamp_datetime_to_float(dt_timestamp : datetime) -> int: return math.floor(dt_timestamp.timestamp()) def timestamp_datetime_to_int(dt_timestamp : datetime) -> int: return math.floor(timestamp_datetime_to_float(dt_timestamp)) def timestamp_string_to_float(str_timestamp : str) -> float: return datetime.timestamp(dateutil.parser.isoparse(str_timestamp)) return timestamp_datetime_to_float(dateutil.parser.isoparse(str_timestamp)) def timestamp_float_to_string(flt_timestamp : float) -> str: return datetime.utcfromtimestamp(flt_timestamp).isoformat() + 'Z' def timestamp_utcnow_to_datetime() -> datetime: return datetime.now(tz=timezone.utc) def timestamp_utcnow_to_float() -> float: return datetime.timestamp(datetime.now(tz=timezone.utc)) return timestamp_datetime_to_float(timestamp_utcnow_to_datetime())