[Python-checkins] CVS: python/nondist/sandbox/datetime datetime.py,1.56,1.57
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 19 Mar 2002 09:09:53 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv5819
Modified Files:
datetime.py
Log Message:
- Fix datetime.__repr__() not to use "days=" (it's redundant).
- Fix comment for datetime.isoformat().
- Update datetimetz class:
- add isoformat()
- add __repr__
- add tzinfo(), utcoffset(), tzname(), dst() methods
- fix return value of __cmp__ when equal
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.56
retrieving revision 1.57
diff -C2 -d -r1.56 -r1.57
*** datetime.py 18 Mar 2002 23:06:30 -0000 1.56
--- datetime.py 19 Mar 2002 17:09:51 -0000 1.57
***************
*** 397,404 ****
def __repr__(self):
if self.__microseconds:
! return "%s(days=%d, %d, %d)" % (self.__class__.__name__,
! self.__days,
! self.__seconds,
! self.__microseconds)
if self.__seconds:
return "%s(%d, %d)" % (self.__class__.__name__,
--- 397,404 ----
def __repr__(self):
if self.__microseconds:
! return "%s(%d, %d, %d)" % (self.__class__.__name__,
! self.__days,
! self.__seconds,
! self.__microseconds)
if self.__seconds:
return "%s(%d, %d)" % (self.__class__.__name__,
***************
*** 915,919 ****
"""Return the time formatted according to ISO.
! This is 'YYYY-MM-DD HH:MM:SS.mmmmmm-xx:yy'
where -xx:yy is the timezone offset.
--- 915,919 ----
"""Return the time formatted according to ISO.
! This is 'YYYY-MM-DD HH:MM:SS.mmmmmm'
where -xx:yy is the timezone offset.
***************
*** 935,938 ****
--- 935,941 ----
class datetimetz(datetime):
+ # XXX needs docstrings and conversion APIs
+ # See http://www.zope.org/Members/fdrake/DateTimeWiki/TimeZoneInfo
+
def __init__(self, year, month, day, hour=0, minute=0, second=0,
microsecond=0, tzinfo=None):
***************
*** 946,949 ****
--- 949,999 ----
self.__tzinfo = tzinfo
+ def isoformat(self, sep='T'):
+ s = super(datetimetz, self).isoformat(sep)
+ if self.__tzinfo is not None:
+ off = self.__tzinfo.utcoffset(self)
+ if off is not None:
+ if off < 0:
+ sign = "-"
+ off = -off
+ else:
+ sign = "+"
+ hh, mm = divmod(off, 60)
+ s = s + "%s%02d:%02d" % (sign, hh, mm)
+ return s
+
+ def __repr__(self):
+ s = super(datetimetz, self).__repr__()
+ if self.__tzinfo is not None:
+ assert s[-1:] == ")"
+ s = s[:-1] + ", tzinfo=%r" % self.__tzinfo + ")"
+ return s
+
+ # XXX property or method?
+ #tzinfo = property(lambda self: self.__tzinfo, doc="timezone info object")
+ def tzinfo(self):
+ return self.__tzinfo
+
+ def utcoffset(self):
+ tz = self.__tzinfo
+ if tz is None:
+ return None
+ else:
+ return tz.utcoffset(self)
+
+ def tzname(self):
+ tz = self.__tzinfo
+ if tz is None:
+ return None
+ else:
+ return tz.tzname(self)
+
+ def dst(self):
+ tz = self.__tzinfo
+ if tz is None:
+ return None
+ else:
+ return tz.dst(self)
+
def __hash__(self):
tz = self.__tzinfo
***************
*** 1010,1014 ****
return -1
if diff == timedelta():
! return 1
return 1
--- 1060,1064 ----
return -1
if diff == timedelta():
! return 0
return 1