[Python-checkins] CVS: python/nondist/sandbox/datetime datetime.py,1.36,1.37
Tim Peters
tim_one@users.sourceforge.net
Sun, 03 Mar 2002 19:01:17 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv23783
Modified Files:
datetime.py
Log Message:
datetime.__add__(): when adding a timedelta, let tmxxx handle the
normalization (Guido remarked on the Wiki that this is what he wanted
normalization for -- finally got around to it <wink>).
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** datetime.py 4 Mar 2002 02:43:56 -0000 1.36
--- datetime.py 4 Mar 2002 03:01:14 -0000 1.37
***************
*** 654,671 ****
"""
if isinstance(other, timedelta):
! hh, mm, ss, us = (self.__hour,
! self.__minute,
! self.__second + other.seconds,
! self.__microsecond + other.microseconds)
! carry_ss, us = divmod(us, 1000000)
! carry_mm, ss = divmod(ss+carry_ss, 60)
! carry_hh, mm = divmod(mm+carry_mm, 60)
! days, hh = divmod(hh+carry_hh, 24)
! result = datetime.fromordinal(days + other.days + self.toordinal())
! result.__hour = hh
! result.__minute = mm
! result.__second = ss
! result.__microsecond = us
! result.__tzoffset = self.__tzoffset
return result
elif isinstance(other, (int, long)):
--- 654,667 ----
"""
if isinstance(other, timedelta):
! t = tmxxx(self.__year,
! self.__month,
! self.__day + other.days,
! self.__hour,
! self.__minute,
! self.__second + other.seconds,
! self.__microsecond + other.microseconds)
! result = datetime.new(t.year, t.month, t.day,
! t.hour, t.minute, t.second,
! t.microsecond, self.__tzoffset)
return result
elif isinstance(other, (int, long)):