summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéonard Gérard <34161+leolchat@users.noreply.github.com>2020-07-01 23:15:12 -0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-11-12 08:50:25 +0100
commit4c9a241949067fc8d55f3ea12170ad364bd8b18d (patch)
tree9f69f4c456466e389af5a3bbe214733aae2841de
parentd08f8dd0f4607a72f1d5497467a2f0cf5a8ee5d4 (diff)
downloadpython-systemd-4c9a241949067fc8d55f3ea12170ad364bd8b18d.tar.gz
Fix seek_realtime to work with timezone aware date
`strftime("%s")` is not in the official python documentation but in my system (ubuntu 18.04 python 3.6.9) it is not aware of the object timezone and will return the wrong value if the timezone is specified and is not the system local one. There are multiple ways to ensure a python `datetime.datetime` is in local timezone, the easiest (with python 3.3+) is to call `.astimezone()` If one wants to support earlier versions of python an extra dependency might be needed like `dateutil.tz.tzlocal()`.
-rw-r--r--systemd/journal.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/systemd/journal.py b/systemd/journal.py
index cc0b8aa..4168dec 100644
--- a/systemd/journal.py
+++ b/systemd/journal.py
@@ -321,7 +321,7 @@ class Reader(_Reader):
>>> j.seek_realtime(yesterday)
"""
if isinstance(realtime, _datetime.datetime):
- realtime = int(float(realtime.strftime("%s.%f")) * 1000000)
+ realtime = int(float(realtime.astimezone().strftime("%s.%f")) * 1000000)
elif not isinstance(realtime, int):
realtime = int(realtime * 1000000)
return super(Reader, self).seek_realtime(realtime)