diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-06-16 17:51:35 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-06-16 17:51:35 +0300 |
commit | 95c8a0ca221e157660e7d8b1278299809c1d19fa (patch) | |
tree | 34cd88d942e592c9fb49f85682a17541e1c17b6f /vk/user.py | |
parent | log user's "last seen" time if they're online (diff) | |
download | vk-scripts-95c8a0ca221e157660e7d8b1278299809c1d19fa.tar.gz vk-scripts-95c8a0ca221e157660e7d8b1278299809c1d19fa.zip |
make "last seen" timestamps timezone-aware
Diffstat (limited to 'vk/user.py')
-rw-r--r-- | vk/user.py | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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] = {} |