Skip to content

Commit 4c9a241

Browse files
leolchatkeszybz
authored andcommitted
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()`.
1 parent d08f8dd commit 4c9a241

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

systemd/journal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def seek_realtime(self, realtime):
321321
>>> j.seek_realtime(yesterday)
322322
"""
323323
if isinstance(realtime, _datetime.datetime):
324-
realtime = int(float(realtime.strftime("%s.%f")) * 1000000)
324+
realtime = int(float(realtime.astimezone().strftime("%s.%f")) * 1000000)
325325
elif not isinstance(realtime, int):
326326
realtime = int(realtime * 1000000)
327327
return super(Reader, self).seek_realtime(realtime)

0 commit comments

Comments
 (0)