Philipp Hörist pushed to branch master at gajim / gajim


Commits:
daabc910 by Philipp Hörist at 2022-10-09T14:58:09+02:00
refactor: Remove usage of utc* datetime methods

datetime.utcnow()
datetime.utcfromtimestamp()

These methods are discouraged according to pythons documentation

- - - - -


3 changed files:

- gajim/common/dbus/location.py
- gajim/gtk/filetransfer.py
- gajim/gtk/history_sync.py


Changes:

=====================================
gajim/common/dbus/location.py
=====================================
@@ -21,6 +21,7 @@
 
 import logging
 from datetime import datetime
+from datetime import timezone
 
 from gi.repository import Gio
 from gi.repository import GLib
@@ -76,7 +77,7 @@ def _on_location_update(self, simple: Geoclue.Simple, *args: 
Any) -> None:
 
         # update data with info we just received
         self._data = {'lat': lat, 'lon': lon, 'alt': alt, 'accuracy': acc}
-        self._data['timestamp'] = self._timestamp_to_utc(timestamp)
+        self._data['timestamp'] = self._timestamp_to_string(timestamp)
         self._send_location()
 
     def _on_client_update(self,
@@ -132,6 +133,6 @@ def _send_location(self) -> None:
         self._emit(info)
 
     @staticmethod
-    def _timestamp_to_utc(timestamp: float) -> str:
-        time = datetime.utcfromtimestamp(timestamp)
-        return time.strftime('%Y-%m-%dT%H:%MZ')
+    def _timestamp_to_string(timestamp: float) -> str:
+        utc_datetime = datetime.fromtimestamp(timestamp, timezone.utc)
+        return utc_datetime.strftime('%Y-%m-%dT%H:%MZ')


=====================================
gajim/gtk/filetransfer.py
=====================================
@@ -28,6 +28,7 @@
 from enum import IntEnum
 from enum import unique
 from datetime import datetime
+from datetime import timezone
 
 from gi.repository import Gtk
 from gi.repository import Gdk
@@ -710,7 +711,7 @@ def get_iter_by_sid(self, typ, sid):
     @staticmethod
     def __convert_date(epoch: float) -> str:
         # Converts date-time from seconds from epoch to iso 8601
-        dt = datetime.utcfromtimestamp(epoch)
+        dt = datetime.fromtimestamp(epoch, timezone.utc)
         return dt.isoformat() + 'Z'
 
     def get_send_file_props(self,


=====================================
gajim/gtk/history_sync.py
=====================================
@@ -20,6 +20,7 @@
 import logging
 from datetime import datetime
 from datetime import timedelta
+from datetime import timezone
 
 from gi.repository import Gtk
 from gi.repository import GLib
@@ -55,7 +56,7 @@ def __init__(self, account: str) -> None:
         self._client = app.get_client(account)
 
         self._timedelta: Optional[timedelta] = None
-        self._now = datetime.utcnow()
+        self._now = datetime.now(timezone.utc)
         self._query_id: Optional[str] = None
         self._start: Optional[datetime] = None
         self._end: Optional[datetime] = None
@@ -69,9 +70,10 @@ def __init__(self, account: str) -> None:
         if mam_start == ArchiveState.NEVER:
             self._current_start = self._now
         elif mam_start == ArchiveState.ALL:
-            self._current_start = datetime.utcfromtimestamp(0)
+            self._current_start = datetime.fromtimestamp(0, timezone.utc)
         else:
-            self._current_start = datetime.fromtimestamp(mam_start)
+            self._current_start = datetime.fromtimestamp(mam_start,
+                                                         timezone.utc)
 
         self.add_button('synchronize', _('Synchronize'), 'suggested-action')
         self.add_button('close', _('Close'))



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/daabc9105ae684214894030d674edf9b11173c7f

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/daabc9105ae684214894030d674edf9b11173c7f
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to