Commit a0c7b502 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Tools - TimeStamp:

- Added methods to manage dattime objects
- Updated existing methods accordingly
parent b9a8208e
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -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())