diff --git a/lib/tz.py b/lib/tz.py index f7d9e451..e353f9b6 100644 --- a/lib/tz.py +++ b/lib/tz.py @@ -50,8 +50,9 @@ class FixedOffsetTimezone(datetime.tzinfo): self._name = name def __repr__(self): + offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ - % (self._offset.seconds // 60, self._name) + % (offset_mins, self._name) def utcoffset(self, dt): return self._offset diff --git a/tests/test_dates.py b/tests/test_dates.py index b310287d..026561a2 100755 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -25,7 +25,7 @@ import math import unittest import psycopg2 -from psycopg2.tz import FixedOffsetTimezone +from psycopg2.tz import FixedOffsetTimezone, ZERO from testconfig import dsn class CommonDatetimeTestsMixin: @@ -513,6 +513,25 @@ class FromTicksTestCase(unittest.TestCase): time(0, 11, 59, 999920)) +class FixedOffsetTimezoneTests(unittest.TestCase): + + def test_init_with_no_args(self): + tzinfo = FixedOffsetTimezone() + self.assert_(tzinfo._offset is ZERO) + self.assert_(tzinfo._name is None) + + def test_repr_with_positive_offset(self): + tzinfo = FixedOffsetTimezone(5 * 60) + self.assertEqual(repr(tzinfo), "psycopg2.tz.FixedOffsetTimezone(offset=300, name=None)") + + def test_repr_with_negative_offset(self): + tzinfo = FixedOffsetTimezone(-5 * 60) + self.assertEqual(repr(tzinfo), "psycopg2.tz.FixedOffsetTimezone(offset=-300, name=None)") + + def test_repr_with_name(self): + tzinfo = FixedOffsetTimezone(name="FOO") + self.assertEqual(repr(tzinfo), "psycopg2.tz.FixedOffsetTimezone(offset=0, name='FOO')") + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__)