[issue10827] Functions in time module should support year < 1900 when accept2dyear = 0
Alexander Belopolsky
report at bugs.python.org
Tue Jan 4 20:02:41 CET 2011
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
On Tue, Jan 4, 2011 at 1:49 PM, Georg Brandl <report at bugs.python.org> wrote:
..
> But if it fails, why not just let it fail?
>
Sure. That's what I meant by fixing the patch. See new patch attached.
----------
Added file: http://bugs.python.org/file20261/issue10827a.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10827>
_______________________________________
-------------- next part --------------
Index: Modules/timemodule.c
===================================================================
--- Modules/timemodule.c (revision 87738)
+++ Modules/timemodule.c (working copy)
@@ -355,21 +355,20 @@
if (y < 1900) {
PyObject *accept = PyDict_GetItemString(moddict,
"accept2dyear");
- if (accept == NULL || !PyLong_CheckExact(accept) ||
- !PyObject_IsTrue(accept)) {
- PyErr_SetString(PyExc_ValueError,
- "year >= 1900 required");
+ int acceptval = accept != NULL && PyObject_IsTrue(accept);
+ if (acceptval == -1)
return 0;
+ if (acceptval) {
+ if (69 <= y && y <= 99)
+ y += 1900;
+ else if (0 <= y && y <= 68)
+ y += 2000;
+ else {
+ PyErr_SetString(PyExc_ValueError,
+ "year out of range");
+ return 0;
+ }
}
- if (69 <= y && y <= 99)
- y += 1900;
- else if (0 <= y && y <= 68)
- y += 2000;
- else {
- PyErr_SetString(PyExc_ValueError,
- "year out of range");
- return 0;
- }
}
p->tm_year = y - 1900;
p->tm_mon--;
More information about the Python-bugs-list
mailing list