From: Douglas Bagnall Date: Wed, 28 Feb 2024 03:51:41 +0000 (+1300) Subject: python:nt_time: add string_from_nt_time X-Git-Tag: tdb-1.4.11~1648 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33a8ae1748ae02435b0097366085ddaabb503dc8;p=thirdparty%2Fsamba.git python:nt_time: add string_from_nt_time Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/nt_time.py b/python/samba/nt_time.py index 5feabb06ff9..4d77bebcde1 100644 --- a/python/samba/nt_time.py +++ b/python/samba/nt_time.py @@ -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()