[Zope3-checkins] CVS: Zope3/lib/python/datetime - _datetime.py:1.15 doc.txt:1.4

Tim Peters tim.one@comcast.net
Sun, 22 Dec 2002 15:45:56 -0500


Update of /cvs-repository/Zope3/lib/python/datetime
In directory cvs.zope.org:/tmp/cvs-serv3035/lib/python/datetime

Modified Files:
	_datetime.py doc.txt 
Log Message:
I give up:  unless I write my own strftime by hand, datetime just can't
be trusted with years before 1900, so now we raise ValueError if a date or
datetime or datetimetz .strftime() method is called with a year before
1900.


=== Zope3/lib/python/datetime/_datetime.py 1.14 => 1.15 ===
--- Zope3/lib/python/datetime/_datetime.py:1.14	Sat Dec 21 21:02:20 2002
+++ Zope3/lib/python/datetime/_datetime.py	Sun Dec 22 15:45:25 2002
@@ -164,6 +164,10 @@
 
 # Correctly substitute for %z and %Z escapes in strftime formats.
 def _wrap_strftime(object, format, timetuple):
+    year = timetuple[0]
+    if year < 1900:
+        raise ValueError("year=%d is before 1900; the datetime strftime() "
+                         "methods require year >= 1900" % year)
     # Don't call _utcoffset() or tzname() unless actually needed.
     zreplace = None # the string to use for %z
     Zreplace = None # the string to use for %Z
@@ -911,7 +915,9 @@
         """Format using strftime().  The date part of the timestamp passed
         to underlying strftime should not be used.
         """
-        timetuple = (0, 0, 0,
+        # The year must be >= 1900 else Python's strftime implementation
+        # can raise a bogus exception.
+        timetuple = (1900, 0, 0,
                      self.__hour, self.__minute, self.__second,
                      0, 0, -1)
         return _wrap_strftime(self, fmt, timetuple)


=== Zope3/lib/python/datetime/doc.txt 1.3 => 1.4 ===
--- Zope3/lib/python/datetime/doc.txt:1.3	Sun Dec 22 15:02:19 2002
+++ Zope3/lib/python/datetime/doc.txt	Sun Dec 22 15:45:25 2002
@@ -159,8 +159,8 @@
 although not all objects support a timetuple() method.
 
 For time and timetz objects, format codes for year, month, and day
-should not be used, as time objects have no such values.  0 is used
-instead.
+should not be used, as time objects have no such values.  1900 is
+used for the year, and 0 for the month and day.
 
 For date objects, format codes for hours, minutes, and seconds should
 not be used, as date objects have no such values.  0 is used insted.
@@ -188,9 +188,8 @@
 additional format codes.
 
 The exact range of years for which strftime() works also varies
-across platforms.  For example, Microsoft's implementation of
-strftime() refuses to accept years before 1900, and Python inherits
-this limitation.
+across platforms.  Regardless of platform, years before 1900 cannot
+be used.
 
 
 class timedelta