diff --git a/src/borg/helpers/time.py b/src/borg/helpers/time.py index e3aa8fa35..b86060080 100644 --- a/src/borg/helpers/time.py +++ b/src/borg/helpers/time.py @@ -114,13 +114,15 @@ class OutputTimestamp: self.ts = ts def __format__(self, format_spec): - return format_time(self.ts, format_spec=format_spec) + # we want to output a timestamp in the user's local timezone + return format_time(self.ts.astimezone(), format_spec=format_spec) def __str__(self): return f"{self}" def isoformat(self): - return self.ts.isoformat(timespec="microseconds") + # we want to output a timestamp in the user's local timezone + return self.ts.astimezone().isoformat(timespec="microseconds") to_json = isoformat diff --git a/src/borg/testsuite/archiver/transfer_cmd.py b/src/borg/testsuite/archiver/transfer_cmd.py index 9a54b2785..7f7b915ed 100644 --- a/src/borg/testsuite/archiver/transfer_cmd.py +++ b/src/borg/testsuite/archiver/transfer_cmd.py @@ -2,7 +2,6 @@ import json import os import stat import tarfile -from datetime import timezone import unittest from ...constants import * # NOQA @@ -48,9 +47,10 @@ class ArchiverTestCase(ArchiverTestCaseBase): repo12_tar = os.path.join(os.path.dirname(__file__), "repo12.tar.gz") repo12_tzoffset = "+01:00" # timezone used to create the repo/archives/json dumps inside the tar file - def local_to_utc(local_naive, tzoffset, tzinfo): + def convert_tz(local_naive, tzoffset, tzinfo): # local_naive was meant to be in tzoffset timezone (e.g. "+01:00"), - # but we want it non-naive in tzinfo time zone (e.g. timezone.utc). + # but we want it non-naive in tzinfo time zone (e.g. timezone.utc + # or None if local timezone is desired). ts = parse_timestamp(local_naive + tzoffset) return ts.astimezone(tzinfo).isoformat(timespec="microseconds") @@ -85,10 +85,10 @@ class ArchiverTestCase(ArchiverTestCaseBase): del expected_archive["barchive"] # timestamps: # borg 1.2 transformed to local time and had microseconds = 0, no tzoffset - # borg 2 uses an utc timestamp, with microseconds and with tzoffset + # borg 2 uses local time, with microseconds and with tzoffset for key in "start", "time": - # fix expectation: local time meant +01:00, so we convert that to utc +00:00 - expected_archive[key] = local_to_utc(expected_archive[key], repo12_tzoffset, timezone.utc) + # fix expectation: local time meant +01:00, so we convert that to whatever local tz is here. + expected_archive[key] = convert_tz(expected_archive[key], repo12_tzoffset, None) # set microseconds to 0, so we can compare got with expected. got_ts = parse_timestamp(got_archive[key]) got_archive[key] = got_ts.replace(microsecond=0).isoformat(timespec="microseconds") @@ -125,7 +125,7 @@ class ArchiverTestCase(ArchiverTestCaseBase): for key in "mtime", "ctime", "atime": if key in e: - e[key] = local_to_utc(e[key], repo12_tzoffset, timezone.utc) + e[key] = convert_tz(e[key], repo12_tzoffset, None) # borg 1 used hardlink slaves linking back to their hardlink masters. # borg 2 uses symmetric approach: just normal items. if they are hardlinks,