diff options
author | Philipp Hörist <philipp@hoerist.com> | 2022-10-09 15:58:09 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2022-10-09 15:58:09 +0300 |
commit | daabc9105ae684214894030d674edf9b11173c7f (patch) | |
tree | eeffa5e67f0943387b1bb114e1d53c95736be7c4 | |
parent | f12cf65e8c44105b3689d5519583475142276a18 (diff) |
refactor: Remove usage of utc* datetime methods
datetime.utcnow()
datetime.utcfromtimestamp()
These methods are discouraged according to pythons documentation
-rw-r--r-- | gajim/common/dbus/location.py | 9 | ||||
-rw-r--r-- | gajim/gtk/filetransfer.py | 3 | ||||
-rw-r--r-- | gajim/gtk/history_sync.py | 8 |
3 files changed, 12 insertions, 8 deletions
diff --git a/gajim/common/dbus/location.py b/gajim/common/dbus/location.py index dbb645aed..58d78a0e4 100644 --- a/gajim/common/dbus/location.py +++ b/gajim/common/dbus/location.py @@ -21,6 +21,7 @@ from typing import Optional import logging from datetime import datetime +from datetime import timezone from gi.repository import Gio from gi.repository import GLib @@ -76,7 +77,7 @@ class LocationListener: # 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 @@ class LocationListener: 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') diff --git a/gajim/gtk/filetransfer.py b/gajim/gtk/filetransfer.py index b4723f06b..c9906dca7 100644 --- a/gajim/gtk/filetransfer.py +++ b/gajim/gtk/filetransfer.py @@ -28,6 +28,7 @@ from functools import partial 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 @@ class FileTransfersWindow: @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, diff --git a/gajim/gtk/history_sync.py b/gajim/gtk/history_sync.py index 42e1620a3..bb87c31f4 100644 --- a/gajim/gtk/history_sync.py +++ b/gajim/gtk/history_sync.py @@ -20,6 +20,7 @@ from typing import Optional 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 @@ class HistorySyncAssistant(Assistant, EventHelper): 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 @@ class HistorySyncAssistant(Assistant, EventHelper): 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')) |