From 02d08085d45aca2fb3f315e94da8ac7b2fcc50e7 Mon Sep 17 00:00:00 2001 From: Nils Uhrberg Date: Thu, 12 Sep 2024 20:08:43 +0200 Subject: [PATCH] feat: Add the ability to add a niceML formatted timestamp based on a given datetime object The timestmap format used in niceml has a special foramt. If it is necessary to create this, it can now be created based on a given datetime object. --- niceml/utilities/timeutils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/niceml/utilities/timeutils.py b/niceml/utilities/timeutils.py index f4f77b7a..ee4c7a15 100644 --- a/niceml/utilities/timeutils.py +++ b/niceml/utilities/timeutils.py @@ -1,14 +1,19 @@ """Module for time related utilities""" + from datetime import datetime +from typing import Optional -def generate_timestamp() -> str: +def generate_timestamp(current_ts: Optional[datetime] = None) -> str: """Generates the timestamp to be used by versioning + Args: + current_ts: Optional datetime object that can be used to create a formatted timestamp. + Returns: String representation of the current timestamp """ - current_ts = datetime.now() + current_ts = current_ts or datetime.now() fmt = ( "{d.year:04d}-{d.month:02d}-{d.day:02d}T{d.hour:02d}" ".{d.minute:02d}.{d.second:02d}.{ms:03d}Z"