diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-01-08 01:56:31 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-01-08 01:56:31 (GMT) |
commit | 73ea29cb039318a70b3cbc9ab2697308a470b5ba (patch) | |
tree | 9b94a94e1298e0d3d9113847fe6c2372061ab3d3 /Modules/timemodule.c | |
parent | 0dd06f4082355451847e686d6adb2f1a9f749adb (diff) | |
download | cpython-73ea29cb039318a70b3cbc9ab2697308a470b5ba.zip cpython-73ea29cb039318a70b3cbc9ab2697308a470b5ba.tar.gz cpython-73ea29cb039318a70b3cbc9ab2697308a470b5ba.tar.bz2 |
Issue #1777412: strftime() accepts year >= 1 instead of year >= 1900
* With Visual Studio, year have to be in [1; 9999]
* Add more tests on the year field
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 46c90ec..de1588f 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -474,15 +474,21 @@ time_strftime(PyObject *self, PyObject *args) else if (!gettmarg(tup, &buf) || !checktm(&buf)) return NULL; - /* XXX: Reportedly, some systems have issues formating dates prior to year - * 1000. These systems should be identified and this check should be - * moved to appropriate system specific section below. */ - if (buf.tm_year < -900) { - PyErr_Format(PyExc_ValueError, "year=%d is before 1900; " - "the strftime() method requires year >= 1900", +#ifdef _MSC_VER + if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) { + PyErr_Format(PyExc_ValueError, + "strftime() requires year in [1; 9999]", buf.tm_year + 1900); return NULL; } +#else + if (buf.tm_year + 1900 < 1) { + PyErr_Format(PyExc_ValueError, + "strftime() requires year >= 1", + buf.tm_year + 1900); + return NULL; + } +#endif /* Normalize tm_isdst just in case someone foolishly implements %Z based on the assumption that tm_isdst falls within the range of |