--- - 2010-06-17 12:41:51.000000000 -0400 +++ Lib/datetime.py 2010-06-17 12:40:19.000000000 -0400 @@ -180,6 +180,7 @@ raise ValueError("year=%d is before 1900; the datetime strftime() " "methods require year >= 1900" % year) # Don't call _utcoffset() or tzname() unless actually needed. + freplace = None # the string to use for %f zreplace = None # the string to use for %z Zreplace = None # the string to use for %Z @@ -194,7 +195,12 @@ if i < n: ch = format[i] i += 1 - if ch == 'z': + if ch == 'f': + if freplace is None: + freplace = '%06d' % getattr(object, + 'microsecond', 0) + newformat.append(freplace) + elif ch == 'z': if zreplace is None: zreplace = "" if hasattr(object, "_utcoffset"): @@ -570,6 +576,9 @@ s = s + ".%06d" % self.__microseconds return s + def total_seconds(self): + return ((self.days * 86400 + self.seconds)*10**6 + + self.microseconds).__truediv__(10**6) days = property(lambda self: self.__days, doc="days") seconds = property(lambda self: self.__seconds, doc="seconds") microseconds = property(lambda self: self.__microseconds, @@ -790,6 +799,11 @@ "Format using strftime()." return _wrap_strftime(self, fmt, self.timetuple()) + def __format__(self, fmt): + if len(fmt) != 0: + return self.strftime(fmt) + return str(self) + def isoformat(self): """Return the date formatted according to ISO. @@ -1249,6 +1263,11 @@ 0, 1, -1) return _wrap_strftime(self, fmt, timetuple) + def __format__(self, fmt): + if len(fmt) != 0: + return self.strftime(fmt) + return str(self) + # Timezone functions def utcoffset(self): @@ -1587,7 +1606,9 @@ @classmethod def strptime(cls, date_string, format): 'string, format -> new datetime parsed from a string (like time.strptime()).' - return cls(*_time.strptime(date_string, format)[0:6]) + import _strptime + tt, us = _strptime._strptime(date_string, format) + return cls(*(tt[0:6] + (us,))) def utcoffset(self): """Return the timezone offset in minutes east of UTC (negative west of