From 73ea29cb039318a70b3cbc9ab2697308a470b5ba Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 8 Jan 2011 01:56:31 +0000 Subject: 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 --- Modules/timemodule.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'Modules/timemodule.c') diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 46c90ecdc9..de1588f0e1 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 -- cgit v1.2.1