[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.86,1.87

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月09日 11:01:36 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv31370
Modified Files:
	datetime.py 
Log Message:
Make str() a synonym for isoformat() (except for datetime, where it's
like isoformat(' ')). The isoformat()s will be changed next to elide
trailing microseconds when they're all zeroes.
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.86
retrieving revision 1.87
diff -C2 -d -r1.86 -r1.87
*** datetime.py	9 Dec 2002 18:56:10 -0000	1.86
--- datetime.py	9 Dec 2002 19:01:33 -0000	1.87
***************
*** 564,571 ****
 self.__month,
 self.__day)
 
! def __str__(self):
! "Convert to string, for str()."
! return self.isoformat()
 
 # Read-only field accessors
--- 564,592 ----
 self.__month,
 self.__day)
+ # XXX These shouldn't depend on time.localtime(), because that
+ # clips the usable dates to [1970 .. 2038). At least ctime() is
+ # easily done without using strftime() -- that's better too because
+ # strftime("%c", ...) is locale specific.
 
! def ctime(self):
! "Format a la ctime()."
! return tmxxx(self.__year, self.__month, self.__day).ctime()
! 
! def strftime(self, fmt):
! "Format using strftime()."
! return _time.strftime(fmt, self.timetuple())
! 
! def isoformat(self):
! """Return the date formatted according to ISO.
! 
! This is 'YYYY-MM-DD'.
! 
! References:
! - http://www.w3.org/TR/NOTE-datetime
! - http://www.cl.cam.ac.uk/~mgk25/iso-time.html
! """
! return "%04d-%02d-%02d" % (self.__year, self.__month, self.__day)
! 
! __str__ = isoformat
 
 # Read-only field accessors
***************
*** 609,627 ****
 return hash(self.__getstate__())
 
- # Formatting methods
- 
- # XXX These shouldn't depend on time.localtime(), because that
- # clips the usable dates to [1970 .. 2038). At least ctime() is
- # easily done without using strftime() -- that's better too because
- # strftime("%c", ...) is locale specific.
- 
- def ctime(self):
- "Format a la ctime()."
- return tmxxx(self.__year, self.__month, self.__day).ctime()
- 
- def strftime(self, fmt):
- "Format using strftime()."
- return _time.strftime(fmt, self.timetuple())
- 
 # Computations
 
--- 630,633 ----
***************
*** 693,707 ****
 return year, week+1, day+1
 
- def isoformat(self):
- """Return the date formatted according to ISO.
- 
- This is 'YYYY-MM-DD'.
- 
- References:
- - http://www.w3.org/TR/NOTE-datetime
- - http://www.cl.cam.ac.uk/~mgk25/iso-time.html
- """
- return "%04d-%02d-%02d" % (self.__year, self.__month, self.__day)
- 
 # Pickle support.
 
--- 699,702 ----
***************
*** 807,830 ****
 self.__microsecond)
 
- # XXX All other types in this module that define isoformat make __str__
- # XXX a synonym, so for now I'm overriding this "pretty string" oddball
- # XXX to do likewise. The last thing I need right now is to spend days
- # XXX arguing about what "pretty" means in 6 distinct types <0.5 wink>.
- def __str__(self):
- """Convert to pretty string, for str()."""
- pretty = "%d:%02d:%02d.%06d" % (
- self.__hour, self.__minute, self.__second,
- self.__microsecond)
- # trim microseconds: hh:mm:ss.xxx000 -> hh:mm:ss.xxx
- while pretty.endswith('0'):
- pretty = pretty[:-1]
- # trim microseconds: hh:mm:ss.000000 -> hh:mm:ss
- if pretty.endswith('.'):
- pretty = pretty[:-1]
- # trim seconds: hh:mm:00 -> hh:mm
- if pretty.endswith(':00'):
- pretty = pretty[:-3]
- return pretty
- 
 __str__ = isoformat
 
--- 802,805 ----
***************
*** 985,996 ****
 return s
 
- # XXX As for time, I'm making __str__ a synonym for isoformat for now.
- def __str__(self):
- """Convert to pretty string, for str()."""
- s = super(timetz, self).__str__()
- tz = self._tzstr()
- if tz: s = "%s %s" % (s, tz)
- return s
- 
 __str__ = isoformat
 
--- 960,963 ----
***************
*** 1166,1170 ****
 
 def __str__(self):
! "Convert to pretty string, for str()."
 return self.isoformat(sep=' ')
 
--- 1133,1137 ----
 
 def __str__(self):
! "Convert to string, for str()."
 return self.isoformat(sep=' ')
 

AltStyle によって変換されたページ (->オリジナル) /