aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/quarg/quassel/formatter.py
diff options
context:
space:
mode:
authorWolfgang Müller2021-05-02 12:38:56 +0200
committerWolfgang Müller2021-05-02 12:38:56 +0200
commitf95a23e0e5c23b7ec13e63501b6ab6df540cb695 (patch)
tree107c181ce88abf258a4fa1cadacdb103d12f63be /quarg/quassel/formatter.py
parent0b6ce2c57d53d947b15f0d429d2216df61ce3783 (diff)
downloadquarg-f95a23e0e5c23b7ec13e63501b6ab6df540cb695.tar.gz
Handle timezones correctly
Quassel uses UTC message timestamps in its database, but does not save any timezone information along with them. Up until now, we were reading those timestamps from the database naively - resulting in datetime objects that could not be identified as UTC. The same happened with timestamps we got from dateutil.isoparse. If the user did not specify an offset explicitly, the timestamp would be parsed and passed to the program "as is", effectively being interpreted as UTC because they were compared to database timestamps. This commit will ensure that the correct timezone is saved for every datetime object we encounter. Timestamps from the database are marked as UTC. If the user does not explicitly specify an offset, the timestamp is assumed to be in local time. Furthermore, when printing out message timestamps, make sure to convert them to the user's local timezone first.
Diffstat (limited to 'quarg/quassel/formatter.py')
-rw-r--r--quarg/quassel/formatter.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/quarg/quassel/formatter.py b/quarg/quassel/formatter.py
index b6235e8..51eec00 100644
--- a/quarg/quassel/formatter.py
+++ b/quarg/quassel/formatter.py
@@ -33,7 +33,9 @@ class Message(NamedTuple):
def format_from(backlog_row):
message = Message.from_backlog(backlog_row)
formatter = FORMATTERS[message.type]
- timestamp = message.time.isoformat(sep=' ', timespec='seconds')
+
+ # make sure to convert timestamps to local time before printing
+ timestamp = message.time.astimezone().isoformat(sep=' ', timespec='seconds')
return f'{timestamp}\t{message.buffer}\t{formatter(message)}'