[Python-checkins] CVS: python/nondist/sandbox/datetime datetime.py,1.30,1.31

Tim Peters tim_one@users.sourceforge.net
Sun, 03 Mar 2002 17:03:16 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv25440

Modified Files:
	datetime.py 
Log Message:
Give tmxxx a toordinal() method, and use it (squash code duplication).


Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** datetime.py	4 Mar 2002 00:53:01 -0000	1.30
--- datetime.py	4 Mar 2002 01:03:14 -0000	1.31
***************
*** 201,209 ****
          self.microsecond = microsecond
  
!     def time(self):
!         "Return Unixish timestamp, as a float (assuming UTC)."
          if self.ordinal is None:
              self.ordinal = _ymd2ord(self.year, self.month, self.day)
!         days = self.ordinal - _ORD1970   # convert to UNIX epoch
          seconds = ((days * 24. + self.hour)*60. + self.minute)*60.
          return seconds + self.second + self.microsecond / 1e6
--- 201,217 ----
          self.microsecond = microsecond
  
!     def toordinal(self):
!         """Return proleptic Gregorian ordinal for the year, month and day.
! 
!         January 1 of year 1 is day 1.  Only the year, month and day values
!         contribute to the result.
!         """
          if self.ordinal is None:
              self.ordinal = _ymd2ord(self.year, self.month, self.day)
!         return self.ordinal
! 
!     def time(self):
!         "Return Unixish timestamp, as a float (assuming UTC)."
!         days = self.toordinal() - _ORD1970   # convert to UNIX epoch
          seconds = ((days * 24. + self.hour)*60. + self.minute)*60.
          return seconds + self.second + self.microsecond / 1e6
***************
*** 211,217 ****
      def ctime(self):
          "Return ctime() style string."
!         if self.ordinal is None:
!             self.ordinal = _ymd2ord(self.year, self.month, self.day)
!         weekday = self.ordinal % 7 or 7
          return "%s %s %2d %02d:%02d:%02d %04d" % (
              _DAYNAMES[weekday - 1],
--- 219,223 ----
      def ctime(self):
          "Return ctime() style string."
!         weekday = self.toordinal() % 7 or 7
          return "%s %s %2d %02d:%02d:%02d %04d" % (
              _DAYNAMES[weekday - 1],