Philipp Hörist pushed to branch master at gajim / python-nbxmpp


Commits:
3959791d by Philipp Hörist at 2026-03-25T22:29:58+01:00
refactor: EntityTime: Simplify getting local datetime

- - - - -
8d0a081b by Philipp Hörist at 2026-03-25T22:30:32+01:00
cq: Fix type annotation

- - - - -


3 changed files:

- nbxmpp/modules/date_and_time.py
- nbxmpp/modules/entity_time.py
- nbxmpp/structs.py


Changes:

=====================================
nbxmpp/modules/date_and_time.py
=====================================
@@ -193,12 +193,3 @@ def parse_datetime(
 
     # convert=None
     return date_time
-
-
-def get_local_time() -> tuple[str, str]:
-    formated_time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
-    isdst = time.localtime().tm_isdst
-    zone = -(time.timezone, time.altzone)[isdst] / 60.0
-    zone = (zone / 60, abs(zone % 60))
-    tzo = "%+03d:%02d" % zone
-    return formated_time, tzo


=====================================
nbxmpp/modules/entity_time.py
=====================================
@@ -8,13 +8,13 @@ from __future__ import annotations
 
 from typing import TYPE_CHECKING
 
+import datetime as dt
 from collections.abc import Callable
 
 from nbxmpp.errors import MalformedStanzaError
 from nbxmpp.errors import StanzaError
 from nbxmpp.modules.base import BaseModule
 from nbxmpp.modules.date_and_time import create_tzinfo
-from nbxmpp.modules.date_and_time import get_local_time
 from nbxmpp.modules.date_and_time import parse_datetime
 from nbxmpp.namespaces import Namespace
 from nbxmpp.protocol import ERR_FORBIDDEN
@@ -91,6 +91,18 @@ class EntityTime(BaseModule):
         raise NodeProcessed
 
 
+def get_local_time() -> tuple[str, str]:
+    utc = dt.datetime.now(tz=dt.timezone.utc)
+    utc_formated = utc.strftime("%Y-%m-%dT%H:%M:%SZ")
+    local = utc.astimezone()
+    if local.utcoffset() == utc.utcoffset():
+        offset = "Z"
+    else:
+        offset = local.strftime("%:z")
+        offset = f"{offset[:-2]}:{offset[-2:]}"
+    return utc_formated, offset
+
+
 def _make_request(jid: JID) -> Iq:
     iq = Iq("get", to=jid)
     iq.addChild("time", namespace=Namespace.TIME)


=====================================
nbxmpp/structs.py
=====================================
@@ -781,7 +781,7 @@ class DiscoIdentity(NamedTuple):
 
 class AdHocCommand(NamedTuple):
     jid: JID
-    node: Node
+    node: str
     name: str | None
     sessionid: str | None = None
     status: AdHocStatus | None = None



View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/648b3376239fc1c59cd2a5bc23285a36741b70be...8d0a081bfcb50f04da91de088834bc225ddfd2c3

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/648b3376239fc1c59cd2a5bc23285a36741b70be...8d0a081bfcb50f04da91de088834bc225ddfd2c3
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to