[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.86,1.87
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 09 Dec 2002 11:01:36 -0800
- Previous message: [Python-checkins] python/nondist/sandbox/datetime datetime.py,1.85,1.86 doc.txt,1.36,1.37
- Next message: [Python-checkins] python/nondist/sandbox/datetime datetime.c,1.50,1.51 datetime.py,1.87,1.88 doc.txt,1.37,1.38 obj_date.c,1.43,1.44 obj_datetime.c,1.42,1.43 obj_time.c,1.5,1.6 test_both.py,1.56,1.57 test_datetime.py,1.58,1.59
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
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=' ')
- Previous message: [Python-checkins] python/nondist/sandbox/datetime datetime.py,1.85,1.86 doc.txt,1.36,1.37
- Next message: [Python-checkins] python/nondist/sandbox/datetime datetime.c,1.50,1.51 datetime.py,1.87,1.88 doc.txt,1.37,1.38 obj_date.c,1.43,1.44 obj_datetime.c,1.42,1.43 obj_time.c,1.5,1.6 test_both.py,1.56,1.57 test_datetime.py,1.58,1.59
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]