diff --git a/pungi/util.py b/pungi/util.py index 6f456cb9..b6ecf6f3 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -807,7 +807,10 @@ def git_ls_remote(baseurl, ref): def get_tz_offset(): """Return a string describing current local timezone offset.""" is_dst = time.daylight and time.localtime().tm_isdst > 0 - offset = time.altzone if is_dst else time.timezone + # We need to negate the value: the values are in seconds west of UTC, but + # ISO 8601 wants the offset to be negative for times behind UTC (i.e. to + # the west). + offset = -(time.altzone if is_dst else time.timezone) hours = offset / 3600 minutes = (offset / 60) % 60 return "%+03d:%02d" % (hours, minutes) diff --git a/tests/test_util.py b/tests/test_util.py index d40073fb..8911458b 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -597,18 +597,18 @@ class TestTZOffset(unittest.TestCase): @mock.patch('time.timezone', new=3600) @mock.patch('time.localtime', new=lambda: mock.Mock(tm_isdst=0)) def test_zone_without_dst(self): - self.assertEqual(util.get_tz_offset(), "+01:00") + self.assertEqual(util.get_tz_offset(), "-01:00") @mock.patch('time.daylight', new=True) @mock.patch('time.altzone', new=7200) @mock.patch('time.timezone', new=3600) @mock.patch('time.localtime', new=lambda: mock.Mock(tm_isdst=0)) def test_with_active_dst(self): - self.assertEqual(util.get_tz_offset(), "+01:00") + self.assertEqual(util.get_tz_offset(), "-01:00") @mock.patch('time.daylight', new=True) - @mock.patch('time.altzone', new=9000) - @mock.patch('time.timezone', new=3600) + @mock.patch('time.altzone', new=-9000) + @mock.patch('time.timezone', new=-3600) @mock.patch('time.localtime', new=lambda: mock.Mock(tm_isdst=1)) def test_with_inactive_dst(self): self.assertEqual(util.get_tz_offset(), "+02:30")