[Python-checkins] r87843 - in python/branches/py3k: Lib/datetime.py Lib/test/datetimetester.py Modules/_datetimemodule.c Modules/timemodule.c

alexander.belopolsky python-checkins at python.org
Sat Jan 8 01:13:34 CET 2011


Author: alexander.belopolsky
Date: Sat Jan  8 01:13:34 2011
New Revision: 87843

Log:
Issue #1777412: extended year range of strftime down to 1000.

Modified:
   python/branches/py3k/Lib/datetime.py
   python/branches/py3k/Lib/test/datetimetester.py
   python/branches/py3k/Modules/_datetimemodule.c
   python/branches/py3k/Modules/timemodule.c

Modified: python/branches/py3k/Lib/datetime.py
==============================================================================
--- python/branches/py3k/Lib/datetime.py	(original)
+++ python/branches/py3k/Lib/datetime.py	Sat Jan  8 01:13:34 2011
@@ -173,9 +173,9 @@
 # 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)
+    if year < 1000:
+        raise ValueError("year=%d is before 1000; the datetime strftime() "
+                         "methods require year >= 1000" % 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
@@ -1189,7 +1189,7 @@
         """Format using strftime().  The date part of the timestamp passed
         to underlying strftime should not be used.
         """
-        # The year must be >= 1900 else Python's strftime implementation
+        # The year must be >= 1000 else Python's strftime implementation
         # can raise a bogus exception.
         timetuple = (1900, 1, 1,
                      self._hour, self._minute, self._second,

Modified: python/branches/py3k/Lib/test/datetimetester.py
==============================================================================
--- python/branches/py3k/Lib/test/datetimetester.py	(original)
+++ python/branches/py3k/Lib/test/datetimetester.py	Sat Jan  8 01:13:34 2011
@@ -1284,10 +1284,10 @@
         self.assertTrue(self.theclass.max)
 
     def test_strftime_out_of_range(self):
-        # For nasty technical reasons, we can't handle years before 1900.
+        # For nasty technical reasons, we can't handle years before 1000.
         cls = self.theclass
-        self.assertEqual(cls(1900, 1, 1).strftime("%Y"), "1900")
-        for y in 1, 49, 51, 99, 100, 1000, 1899:
+        self.assertEqual(cls(1000, 1, 1).strftime("%Y"), "1000")
+        for y in 1, 49, 51, 99, 100, 999:
             self.assertRaises(ValueError, cls(y, 1, 1).strftime, "%Y")
 
     def test_replace(self):

Modified: python/branches/py3k/Modules/_datetimemodule.c
==============================================================================
--- python/branches/py3k/Modules/_datetimemodule.c	(original)
+++ python/branches/py3k/Modules/_datetimemodule.c	Sat Jan  8 01:13:34 2011
@@ -1166,10 +1166,10 @@
     if (!pin)
         return NULL;
 
-    /* Give up if the year is before 1900.
+    /* Give up if the year is before 1000.
      * Python strftime() plays games with the year, and different
      * games depending on whether envar PYTHON2K is set.  This makes
-     * years before 1900 a nightmare, even if the platform strftime
+     * years before 1000 a nightmare, even if the platform strftime
      * supports them (and not all do).
      * We could get a lot farther here by avoiding Python's strftime
      * wrapper and calling the C strftime() directly, but that isn't
@@ -1182,10 +1182,10 @@
         assert(PyLong_Check(pyyear));
         year = PyLong_AsLong(pyyear);
         Py_DECREF(pyyear);
-        if (year < 1900) {
+        if (year < 1000) {
             PyErr_Format(PyExc_ValueError, "year=%ld is before "
-                         "1900; the datetime strftime() "
-                         "methods require year >= 1900",
+                         "1000; the datetime strftime() "
+                         "methods require year >= 1000",
                          year);
             return NULL;
         }
@@ -3663,7 +3663,7 @@
 
     /* Python's strftime does insane things with the year part of the
      * timetuple.  The year is forced to (the otherwise nonsensical)
-     * 1900 to worm around that.
+     * 1900 to work around that.
      */
     tuple = Py_BuildValue("iiiiiiiii",
                           1900, 1, 1, /* year, month, day */

Modified: python/branches/py3k/Modules/timemodule.c
==============================================================================
--- python/branches/py3k/Modules/timemodule.c	(original)
+++ python/branches/py3k/Modules/timemodule.c	Sat Jan  8 01:13:34 2011
@@ -471,9 +471,9 @@
         return NULL;
 
     /* XXX: Reportedly, some systems have issues formating dates prior to year
-     * 1900.  These systems should be identified and this check should be
+     * 1000.  These systems should be identified and this check should be
      * moved to appropriate system specific section below. */
-    if (buf.tm_year < 0) {
+    if (buf.tm_year < -900) {
         PyErr_Format(PyExc_ValueError, "year=%d is before 1900; "
                      "the strftime() method requires year >= 1900",
                      buf.tm_year + 1900);


More information about the Python-checkins mailing list