------------------------------------------------------------------------ r11769 | jomae | 2013-04-10 13:08:01 +0200 (Wed, 10 Apr 2013) | 2 lines 1.0.2dev: merge [11768] from 0.12-stable Index: trac/util/tests/datefmt.py =================================================================== --- trac/util/tests/datefmt.py (revision 11768) +++ trac/util/tests/datefmt.py (revision 11769) @@ -1169,6 +1169,29 @@ self.assertEqual('2011-10-30T02:45:42.123456+01:00', dt.astimezone(datefmt.localtz).isoformat()) + def test_astimezone_invalid_range_on_gmt01(self): + self._tzset('GMT-1') + + # 1899-12-30T23:59:58+00:00 is -0x83ac4e92 for time_t, out of range + # for 32-bit signed integer + dt = datetime.datetime(1899, 12, 30, 23, 59, 58, 123456, datefmt.utc) + self.assertEqual('1899-12-31T00:59:58.123456+01:00', + dt.astimezone(datefmt.localtz).isoformat()) + dt = datetime.datetime(1899, 12, 30, 23, 59, 58, 123456, + datefmt.localtz) + self.assertEqual('1899-12-30T22:59:58.123456+00:00', + dt.astimezone(datefmt.utc).isoformat()) + + # 2040-12-31T23:59:58+00:00 is 0x858c84ee for time_t, out of range for + # 32-bit signed integer + dt = datetime.datetime(2040, 12, 31, 23, 59, 58, 123456, datefmt.utc) + self.assertEqual('2041-01-01T00:59:58.123456+01:00', + dt.astimezone(datefmt.localtz).isoformat()) + dt = datetime.datetime(2040, 12, 31, 23, 59, 58, 123456, + datefmt.localtz) + self.assertEqual('2040-12-31T22:59:58.123456+00:00', + dt.astimezone(datefmt.utc).isoformat()) + def test_arithmetic_localized_non_existent_time(self): self._tzset('Europe/Paris') t = datetime.datetime(2012, 3, 25, 1, 15, 42, 123456) Index: trac/util/datefmt.py =================================================================== --- trac/util/datefmt.py (revision 11768) +++ trac/util/datefmt.py (revision 11769) @@ -842,12 +842,15 @@ def fromutc(self, dt): if dt.tzinfo is None or dt.tzinfo is not self: raise ValueError('fromutc: dt.tzinfo is not self') - tt = time.localtime(to_timestamp(dt.replace(tzinfo=utc))) + try: + tt = time.localtime(to_timestamp(dt.replace(tzinfo=utc))) + except ValueError: + return dt.replace(tzinfo=self._std_tz) + self._std_offset if tt.tm_isdst > 0: tz = self._dst_tz else: tz = self._std_tz - return datetime(microsecond=dt.microsecond, tzinfo=tz, *tt[0:6]) + return datetime(*(tt[:6] + (dt.microsecond, tz))) utc = FixedOffset(0, 'UTC') Index: . =================================================================== --- . (revision 11768) +++ . (revision 11769) Property changes on: . ___________________________________________________________________ Modified: svn:mergeinfo Merged /branches/0.12-stable:r11768 ------------------------------------------------------------------------