Skip to content

Commit

Permalink
Make timestamp helper timezone-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
milkey-mouse committed Nov 5, 2020
1 parent 2c478f4 commit 02974c6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/borg/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def timestamp(s):
try:
# is it pointing to a file / directory?
ts = safe_s(os.stat(s).st_mtime)
return datetime.utcfromtimestamp(ts)
return datetime.fromtimestamp(ts, tz=timezone.utc)
except OSError:
# didn't work, try parsing as timestamp. UTC, no TZ, no microsecs support.
for format in ('%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT%H:%M:%S+00:00',
Expand All @@ -615,7 +615,7 @@ def timestamp(s):
'%Y-%m-%d', '%Y-%j',
):
try:
return datetime.strptime(s, format)
return datetime.strptime(s, format).replace(tzinfo=timezone.utc)
except ValueError:
continue
raise ValueError
Expand Down

0 comments on commit 02974c6

Please sign in to comment.