Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!160Resolve "(CTTC) Forecaster component"
......@@ -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())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment