@@ -416,8 +416,9 @@ iso_week1_monday(int year)
416
416
static int
417
417
iso_to_ymd (const int iso_year , const int iso_week , const int iso_day ,
418
418
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 ;
421
422
}
422
423
if (iso_week <= 0 || iso_week >= 53 ) {
423
424
int out_of_range = 1 ;
@@ -765,7 +766,7 @@ parse_isoformat_date(const char *dtstr, const size_t len, int *year, int *month,
765
766
* -2: Inconsistent date separator usage
766
767
* -3: Failed to parse ISO week.
767
768
* -4: Failed to parse ISO day.
768
- * -5, -6: Failure in iso_to_ymd
769
+ * -5, -6, -7 : Failure in iso_to_ymd
769
770
*/
770
771
const char * p = dtstr ;
771
772
p = parse_digits (p , year , 4 );
@@ -3145,15 +3146,13 @@ date_fromisocalendar(PyObject *cls, PyObject *args, PyObject *kw)
3145
3146
return NULL ;
3146
3147
}
3147
3148
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
-
3154
3149
int month ;
3155
3150
int rv = iso_to_ymd (year , week , day , & year , & month , & day );
3156
3151
3152
+ if (rv == -4 ) {
3153
+ PyErr_Format (PyExc_ValueError , "Year is out of range: %d" , year );
3154
+ return NULL ;
3155
+ }
3157
3156
3158
3157
if (rv == -2 ) {
3159
3158
PyErr_Format (PyExc_ValueError , "Invalid week: %d" , week );
0 commit comments