diff --git a/django/utils/timezone.py b/django/utils/timezone.py index 7586fef750..deabab5176 100644 --- a/django/utils/timezone.py +++ b/django/utils/timezone.py @@ -58,7 +58,7 @@ utc = pytz.utc def get_fixed_timezone(offset): """Return a tzinfo instance with a fixed offset from UTC.""" if isinstance(offset, timedelta): - offset = offset.seconds // 60 + offset = offset.total_seconds() // 60 sign = '-' if offset < 0 else '+' hhmm = '%02d%02d' % divmod(abs(offset), 60) name = sign + hhmm diff --git a/tests/utils_tests/test_timezone.py b/tests/utils_tests/test_timezone.py index 3c0b092d8a..32906f8b88 100644 --- a/tests/utils_tests/test_timezone.py +++ b/tests/utils_tests/test_timezone.py @@ -194,5 +194,9 @@ class TimezoneTests(SimpleTestCase): delta = datetime.timedelta(hours=1) self.assertEqual(timezone.get_fixed_timezone(delta).utcoffset(''), delta) + def test_fixedoffset_negative_timedelta(self): + delta = datetime.timedelta(hours=-2) + self.assertEqual(timezone.get_fixed_timezone(delta).utcoffset(''), delta) + def test_fixedoffset_pickle(self): self.assertEqual(pickle.loads(pickle.dumps(timezone.FixedOffset(0, 'tzname'))).tzname(''), 'tzname')