Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 482034 | Differences between
and this patch

Collapse All | Expand All

(-)trac/util/tests/datefmt.py (+23 lines)
Lines 1169-1174 Link Here
1169
        self.assertEqual('2011-10-30T02:45:42.123456+01:00',
1169
        self.assertEqual('2011-10-30T02:45:42.123456+01:00',
1170
                         dt.astimezone(datefmt.localtz).isoformat())
1170
                         dt.astimezone(datefmt.localtz).isoformat())
1171
1171
1172
    def test_astimezone_invalid_range_on_gmt01(self):
1173
        self._tzset('GMT-1')
1174
1175
        # 1899-12-30T23:59:58+00:00 is -0x83ac4e92 for time_t, out of range
1176
        # for 32-bit signed integer
1177
        dt = datetime.datetime(1899, 12, 30, 23, 59, 58, 123456, datefmt.utc)
1178
        self.assertEqual('1899-12-31T00:59:58.123456+01:00',
1179
                         dt.astimezone(datefmt.localtz).isoformat())
1180
        dt = datetime.datetime(1899, 12, 30, 23, 59, 58, 123456,
1181
                               datefmt.localtz)
1182
        self.assertEqual('1899-12-30T22:59:58.123456+00:00',
1183
                         dt.astimezone(datefmt.utc).isoformat())
1184
1185
        # 2040-12-31T23:59:58+00:00 is 0x858c84ee for time_t, out of range for
1186
        # 32-bit signed integer
1187
        dt = datetime.datetime(2040, 12, 31, 23, 59, 58, 123456, datefmt.utc)
1188
        self.assertEqual('2041-01-01T00:59:58.123456+01:00',
1189
                         dt.astimezone(datefmt.localtz).isoformat())
1190
        dt = datetime.datetime(2040, 12, 31, 23, 59, 58, 123456,
1191
                               datefmt.localtz)
1192
        self.assertEqual('2040-12-31T22:59:58.123456+00:00',
1193
                         dt.astimezone(datefmt.utc).isoformat())
1194
1172
    def test_arithmetic_localized_non_existent_time(self):
1195
    def test_arithmetic_localized_non_existent_time(self):
1173
        self._tzset('Europe/Paris')
1196
        self._tzset('Europe/Paris')
1174
        t = datetime.datetime(2012, 3, 25, 1, 15, 42, 123456)
1197
        t = datetime.datetime(2012, 3, 25, 1, 15, 42, 123456)
(-)trac/util/datefmt.py (-2 / +5 lines)
Lines 842-853 Link Here
842
    def fromutc(self, dt):
842
    def fromutc(self, dt):
843
        if dt.tzinfo is None or dt.tzinfo is not self:
843
        if dt.tzinfo is None or dt.tzinfo is not self:
844
            raise ValueError('fromutc: dt.tzinfo is not self')
844
            raise ValueError('fromutc: dt.tzinfo is not self')
845
        tt = time.localtime(to_timestamp(dt.replace(tzinfo=utc)))
845
        try:
846
            tt = time.localtime(to_timestamp(dt.replace(tzinfo=utc)))
847
        except ValueError:
848
            return dt.replace(tzinfo=self._std_tz) + self._std_offset
846
        if tt.tm_isdst > 0:
849
        if tt.tm_isdst > 0:
847
            tz = self._dst_tz
850
            tz = self._dst_tz
848
        else:
851
        else:
849
            tz = self._std_tz
852
            tz = self._std_tz
850
        return datetime(microsecond=dt.microsecond, tzinfo=tz, *tt[0:6])
853
        return datetime(*(tt[:6] + (dt.microsecond, tz)))
851
854
852
855
853
utc = FixedOffset(0, 'UTC')
856
utc = FixedOffset(0, 'UTC')

Return to bug 482034