Fixed #28739 -- Fixed get_fixed_timezone() for negative timedeltas.

This commit is contained in:
medmunds 2017-10-24 12:42:44 -07:00 committed by Tim Graham
parent 3576bfe07c
commit d1317edad0
2 changed files with 5 additions and 1 deletions

View File

@ -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

View File

@ -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')