]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python:nt_time: add string_from_nt_time
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 28 Feb 2024 03:51:41 +0000 (16:51 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 29 Feb 2024 04:01:40 +0000 (04:01 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/nt_time.py

index 5feabb06ff9926a2bc4804ed990afdc65fcd9ab2..4d77bebcde1223816c46eba18a45aba66502b991 100644 (file)
@@ -100,3 +100,16 @@ def nt_time_from_string(s: str) -> NtTime:
         dt = dt.astimezone()
 
     return nt_time_from_datetime(dt)
+
+
+def string_from_nt_time(nttime: NtTime, format:str=None) -> str:
+    """Format an NtTime date as a string.
+
+    If format is not provided, an ISO 8601 string is used.
+    """
+    dt = datetime_from_nt_time(nttime)
+
+    if format is not None:
+        return dt.strftime(format)
+
+    return dt.isoformat()