14a15,16 > This was originally copied from the sandbox of the CPython CVS repository. > Thanks to Tim Peters for suggesting using it. 578,580c580,584 < return self.__class__(self.__days + other.__days, < self.__seconds + other.__seconds, < self.__microseconds + other.__microseconds) --- > # for CPython compatibility, we cannot use > # our __class__ here, but need a real timedelta > return timedelta(self.__days + other.__days, > self.__seconds + other.__seconds, > self.__microseconds + other.__microseconds) 596,598c600,604 < return self.__class__(-self.__days, < -self.__seconds, < -self.__microseconds) --- > # for CPython compatibility, we cannot use > # our __class__ here, but need a real timedelta > return timedelta(-self.__days, > -self.__seconds, > -self.__microseconds) 611,613c617,621 < return self.__class__(self.__days * other, < self.__seconds * other, < self.__microseconds * other) --- > # for CPython compatibility, we cannot use > # our __class__ here, but need a real timedelta > return timedelta(self.__days * other, > self.__seconds * other, > self.__microseconds * other) 622c630 < return self.__class__(0, 0, usec // other) --- > return timedelta(0, 0, usec // other) 731c739 < self.__setstate((year,)) --- > self.__setstate(year) 904c912 < result = self.__class__(t.year, t.month, t.day) --- > result = date(t.year, t.month, t.day) 967,970c975,977 < def __setstate(self, t): < assert isinstance(t, tuple) and len(t) == 1, `t` < string = t[0] < assert len(string) == 4 --- > def __setstate(self, string): > if len(string) != 4 or not (1 <= ord(string[2]) <= 12): > raise TypeError("not enough arguments") 1093c1100 < self.__setstate((hour, minute or None)) --- > self.__setstate(hour, minute or None) 1331,1335c1338,1340 < def __setstate(self, state): < assert isinstance(state, tuple) < assert 1 <= len(state) <= 2 < string = state[0] < assert len(string) == 6 --- > def __setstate(self, string, tzinfo): > if len(string) != 6 or ord(string[0]) >= 24: > raise TypeError("an integer is required") 1339,1342c1344 < if len(state) == 1: < self._tzinfo = None < else: < self._tzinfo = state[1] --- > self._tzinfo = tzinfo 1345c1347 < return (self.__class__, self.__getstate()) --- > return (time, self.__getstate()) 1363c1365 < self.__setstate((year, month)) --- > self.__setstate(year, month) 1397a1400,1403 > if 1 - (t % 1.0) < 0.000001: > t = float(int(t)) + 1 > if t < 0: > t -= 1 1408a1415,1418 > if 1 - (t % 1.0) < 0.000001: > t = float(int(t)) + 1 > if t < 0: > t -= 1 1562c1572 < while L[-1] == 0: --- > if L[-1] == 0: 1563a1574,1575 > if L[-1] == 0: > del L[-1] 1574a1587,1591 > @classmethod > def strptime(cls, date_string, format): > 'string, format -> new datetime parsed from a string (like time.strptime()).' > return cls(*_time.strptime(date_string, format)[0:6]) > 1627c1644 < elif hasattr(other, "timetuple"): --- > elif hasattr(other, "timetuple") and not isinstance(other, date): 1635c1652 < elif hasattr(other, "timetuple"): --- > elif hasattr(other, "timetuple") and not isinstance(other, date): 1643c1660 < elif hasattr(other, "timetuple"): --- > elif hasattr(other, "timetuple") and not isinstance(other, date): 1651c1668 < elif hasattr(other, "timetuple"): --- > elif hasattr(other, "timetuple") and not isinstance(other, date): 1659c1676 < elif hasattr(other, "timetuple"): --- > elif hasattr(other, "timetuple") and not isinstance(other, date): 1667c1684 < elif hasattr(other, "timetuple"): --- > elif hasattr(other, "timetuple") and not isinstance(other, date): 1715c1732 < result = self.__class__(t.year, t.month, t.day, --- > result = datetime(t.year, t.month, t.day, 1770,1774c1787 < def __setstate(self, state): < assert isinstance(state, tuple) < assert 1 <= len(state) <= 2 < string = state[0] < assert len(string) == 10 --- > def __setstate(self, string, tzinfo): 1779,1782c1792 < if len(state) == 1: < self._tzinfo = None < else: < self._tzinfo = state[1] --- > self._tzinfo = tzinfo 2002,2007d2011 < def _test(): < import test_datetime < test_datetime.test_main() < < if __name__ == "__main__": < _test()