diff --git a/src/common/tools/timestamp/Converters.py b/src/common/tools/timestamp/Converters.py index 0ef8e0863b71b610602dfc0ee4fc7c72d25a1139..7918017390e60bd7830d3513216fc0b8f6cf83ef 100644 --- a/src/common/tools/timestamp/Converters.py +++ b/src/common/tools/timestamp/Converters.py @@ -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())