diff sat/tools/utils.py @ 3877:00212260f659

plugin XEP-0420: Implementation of Stanza Content Encryption: Includes implementation of XEP-0082 (XMPP date and time profiles) and tests for both new plugins. Everything is type checked, linted, format checked and unit tested. Adds new dependency xmlschema. fix 377
author Syndace <me@syndace.dev>
date Tue, 23 Aug 2022 12:04:11 +0200
parents e417c478b488
children 32087d7c25d4
line wrap: on
line diff
--- a/sat/tools/utils.py	Tue Aug 23 23:37:22 2022 +0200
+++ b/sat/tools/utils.py	Tue Aug 23 12:04:11 2022 +0200
@@ -34,6 +34,7 @@
 from twisted.internet import defer
 from sat.core.constants import Const as C
 from sat.core.log import getLogger
+from sat.tools.datetime import format_date, format_datetime
 
 log = getLogger(__name__)
 
@@ -146,18 +147,16 @@
 
     to avoid reveling the timezone, we always return UTC dates
     the string returned by this method is valid with RFC 3339
+    this function redirects to the functions in the :mod:`sat.tools.datetime` module
     @param timestamp(None, float): posix timestamp. If None current time will be used
     @param with_time(bool): if True include the time
     @return(unicode): XEP-0082 formatted date and time
     """
-    template_date = "%Y-%m-%d"
-    template_time = "%H:%M:%SZ"
-    template = (
-        "{}T{}".format(template_date, template_time) if with_time else template_date
+    dtime = datetime.datetime.utcfromtimestamp(
+        time.time() if timestamp is None else timestamp
     )
-    return datetime.datetime.utcfromtimestamp(
-        time.time() if timestamp is None else timestamp
-    ).strftime(template)
+
+    return format_datetime(dtime) if with_time else format_date(dtime.date())
 
 
 def generatePassword(vocabulary=None, size=20):