@@ -416,8 +416,9 @@ iso_week1_monday(int year)
416416static int
417417iso_to_ymd (const int iso_year , const int iso_week , const int iso_day ,
418418 int * year , int * month , int * day ) {
419- if (iso_year <= 0 ) {
420- return -2 ;
419+ // Year is bounded to 0 < year < 10000 because 9999-12-31 is (9999, 52, 5)
420+ if (iso_year < MINYEAR || iso_year > MAXYEAR ) {
421+ return -4 ;
421422 }
422423 if (iso_week <= 0 || iso_week >= 53 ) {
423424 int out_of_range = 1 ;
@@ -765,7 +766,7 @@ parse_isoformat_date(const char *dtstr, const size_t len, int *year, int *month,
765766 * -2: Inconsistent date separator usage
766767 * -3: Failed to parse ISO week.
767768 * -4: Failed to parse ISO day.
768- * -5, -6: Failure in iso_to_ymd
769+ * -5, -6, -7 : Failure in iso_to_ymd
769770 */
770771 const char * p = dtstr ;
771772 p = parse_digits (p , year , 4 );
@@ -3145,15 +3146,13 @@ date_fromisocalendar(PyObject *cls, PyObject *args, PyObject *kw)
31453146 return NULL ;
31463147 }
31473148
3148- // Year is bounded to 0 < year < 10000 because 9999-12-31 is (9999, 52, 5)
3149- if (year < MINYEAR || year > MAXYEAR ) {
3150- PyErr_Format (PyExc_ValueError , "Year is out of range: %d" , year );
3151- return NULL ;
3152- }
3153-
31543149 int month ;
31553150 int rv = iso_to_ymd (year , week , day , & year , & month , & day );
31563151
3152+ if (rv == -4 ) {
3153+ PyErr_Format (PyExc_ValueError , "Year is out of range: %d" , year );
3154+ return NULL ;
3155+ }
31573156
31583157 if (rv == -2 ) {
31593158 PyErr_Format (PyExc_ValueError , "Invalid week: %d" , week );
0 commit comments