Skip to content

Commit

Permalink
Return timestamp from file in UTC, since borg expects UTC (#62)
Browse files Browse the repository at this point in the history
return timestamp from file in UTC, since borg expects UTC timestamps
  • Loading branch information
cr1901 authored Jan 10, 2024
1 parent f7c58e9 commit 1e1b60c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/borg_import/helpers/testsuite/test_timestamps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime
from datetime import datetime, timezone
from pathlib import Path

import pytest
Expand All @@ -11,7 +11,7 @@ def test_datetime_from_mtime(tmpdir):
fn = Path(str(tmpdir.join("mtime_test")))
with fn.open("w"):
pass
dt = datetime(1999, 12, 31, 23, 59, 59)
dt = datetime(1999, 12, 31, 23, 59, 59, tzinfo=timezone.utc)
atime = mtime = dt.timestamp()
os.utime(str(fn), (atime, mtime)) # touch file
assert datetime_from_mtime(fn) == dt
Expand Down
4 changes: 2 additions & 2 deletions src/borg_import/helpers/timestamps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone


def datetime_from_mtime(path):
Expand All @@ -10,7 +10,7 @@ def datetime_from_mtime(path):
at backup time).
"""
t = path.stat().st_mtime
return datetime.fromtimestamp(t)
return datetime.fromtimestamp(t, tz=timezone.utc)


def datetime_from_string(s):
Expand Down

0 comments on commit 1e1b60c

Please sign in to comment.