aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--vk/user.py9
-rw-r--r--vk/utils/tracking/db/record.py6
2 files changed, 10 insertions, 5 deletions
diff --git a/vk/user.py b/vk/user.py
index a895960..8bb57b8 100644
--- a/vk/user.py
+++ b/vk/user.py
@@ -2,7 +2,7 @@
# This file is licensed under the terms of the MIT License.
# See LICENSE.txt for details.
-from datetime import datetime
+from datetime import datetime, timezone
from enum import Enum
from numbers import Real, Integral
@@ -96,7 +96,7 @@ class User:
@staticmethod
def _last_seen_from_timestamp(t):
- return datetime.fromtimestamp(t)
+ return datetime.fromtimestamp(t, timezone.utc)
@staticmethod
def _last_seen_to_timestamp(t):
@@ -116,9 +116,12 @@ class User:
def _get_last_seen(self):
return self._last_seen_from_timestamp(self._impl[Field.LAST_SEEN.value]['time'])
- def get_last_seen(self):
+ def get_last_seen_utc(self):
return self._get_last_seen()
+ def get_last_seen_local(self):
+ return self._get_last_seen().astimezone()
+
def _set_last_seen(self, t):
if Field.LAST_SEEN.value not in self._impl:
self._impl[Field.LAST_SEEN.value] = {}
diff --git a/vk/utils/tracking/db/record.py b/vk/utils/tracking/db/record.py
index e126442..7cb054f 100644
--- a/vk/utils/tracking/db/record.py
+++ b/vk/utils/tracking/db/record.py
@@ -3,12 +3,12 @@
# See LICENSE.txt for details.
from collections import OrderedDict
-from datetime import datetime
+from datetime import datetime, timezone
from vk.user import Field as UserField
def _gen_timestamp():
- return datetime.utcnow().replace(microsecond=0)
+ return datetime.now(timezone.utc).replace(microsecond=0)
class Record:
_USER_FIELDS = (
@@ -51,6 +51,8 @@ class Record:
fields = OrderedDict()
for field in Record._USER_FIELDS:
fields[field] = user[field]
+ if UserField.LAST_SEEN in Record._USER_FIELDS:
+ fields[UserField.LAST_SEEN] = fields[UserField.LAST_SEEN].isoformat()
return Record(fields)
@staticmethod