[Python-checkins] python/dist/src/Modules datetimemodule.c,1.11,1.12
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
2002年12月22日 12:58:44 -0800
- Previous message: [Python-checkins] python/dist/src/Lib/test test_datetime.py,1.6,1.7
- Next message: [Python-checkins] python/nondist/sandbox/twister MersenneTwister.c,1.4,1.5 random.py,1.5,1.6 test_twister.py,1.3,1.4 todo.txt,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv21224/python/Modules
Modified Files:
datetimemodule.c
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.
Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** datetimemodule.c 22 Dec 2002 20:34:46 -0000 1.11
--- datetimemodule.c 22 Dec 2002 20:58:42 -0000 1.12
***************
*** 941,944 ****
--- 941,969 ----
assert(PyString_Check(format));
+ /* Give up if the year is before 1900.
+ * 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
+ * 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
+ * an option in the Python implementation of this module.
+ */
+ {
+ long year;
+ PyObject *pyyear = PySequence_GetItem(timetuple, 0);
+ if (pyyear == NULL) return NULL;
+ assert(PyInt_Check(pyyear));
+ year = PyInt_AsLong(pyyear);
+ Py_DECREF(pyyear);
+ if (year < 1900) {
+ PyErr_Format(PyExc_ValueError, "year=%ld is before "
+ "1900; the datetime strftime() "
+ "methods require year >= 1900",
+ year);
+ return NULL;
+ }
+ }
+
/* Scan the input format, looking for %z and %Z escapes, building
* a new format. Since computing the replacements for those codes
- Previous message: [Python-checkins] python/dist/src/Lib/test test_datetime.py,1.6,1.7
- Next message: [Python-checkins] python/nondist/sandbox/twister MersenneTwister.c,1.4,1.5 random.py,1.5,1.6 test_twister.py,1.3,1.4 todo.txt,1.1,1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]