@@ -66,7 +66,7 @@ This file implements string parsing and creation for NumPy datetime.
6666 *
6767 * Returns 0 on success, -1 on failure.
6868 */
69- int parse_iso_8601_datetime (const char * str , int len ,
69+ int parse_iso_8601_datetime (const char * str , int len , int want_exc ,
7070 npy_datetimestruct * out ,
7171 int * out_local , int * out_tzoffset ) {
7272 int year_leap = 0 ;
@@ -173,8 +173,10 @@ int parse_iso_8601_datetime(const char *str, int len,
173173 goto parse_error ;
174174 }
175175 if (out -> month < 1 || out -> month > 12 ) {
176- PyErr_Format (PyExc_ValueError ,
177- "Month out of range in datetime string \"%s\"" , str );
176+ if (want_exc ) {
177+ PyErr_Format (PyExc_ValueError ,
178+ "Month out of range in datetime string \"%s\"" , str );
179+ }
178180 goto error ;
179181 }
180182
@@ -217,8 +219,10 @@ int parse_iso_8601_datetime(const char *str, int len,
217219 }
218220 if (out -> day < 1 ||
219221 out -> day > days_per_month_table [year_leap ][out -> month - 1 ]) {
220- PyErr_Format (PyExc_ValueError ,
221- "Day out of range in datetime string \"%s\"" , str );
222+ if (want_exc ) {
223+ PyErr_Format (PyExc_ValueError ,
224+ "Day out of range in datetime string \"%s\"" , str );
225+ }
222226 goto error ;
223227 }
224228
@@ -251,8 +255,11 @@ int parse_iso_8601_datetime(const char *str, int len,
251255 ++ substr ;
252256 -- sublen ;
253257 if (out -> hour >= 24 ) {
254- PyErr_Format (PyExc_ValueError ,
255- "Hours out of range in datetime string \"%s\"" , str );
258+ if (want_exc ) {
259+ PyErr_Format (PyExc_ValueError ,
260+ "Hours out of range in datetime string \"%s\"" ,
261+ str );
262+ }
256263 goto error ;
257264 }
258265 }
@@ -291,8 +298,11 @@ int parse_iso_8601_datetime(const char *str, int len,
291298 ++ substr ;
292299 -- sublen ;
293300 if (out -> min >= 60 ) {
294- PyErr_Format (PyExc_ValueError ,
295- "Minutes out of range in datetime string \"%s\"" , str );
301+ if (want_exc ) {
302+ PyErr_Format (PyExc_ValueError ,
303+ "Minutes out of range in datetime string \"%s\"" ,
304+ str );
305+ }
296306 goto error ;
297307 }
298308 } else if (!has_hms_sep ) {
@@ -328,8 +338,11 @@ int parse_iso_8601_datetime(const char *str, int len,
328338 ++ substr ;
329339 -- sublen ;
330340 if (out -> sec >= 60 ) {
331- PyErr_Format (PyExc_ValueError ,
332- "Seconds out of range in datetime string \"%s\"" , str );
341+ if (want_exc ) {
342+ PyErr_Format (PyExc_ValueError ,
343+ "Seconds out of range in datetime string \"%s\"" ,
344+ str );
345+ }
333346 goto error ;
334347 }
335348 } else if (!has_hms_sep ) {
@@ -438,10 +451,12 @@ int parse_iso_8601_datetime(const char *str, int len,
438451 substr += 2 ;
439452 sublen -= 2 ;
440453 if (offset_hour >= 24 ) {
441- PyErr_Format (PyExc_ValueError ,
442- "Timezone hours offset out of range "
443- "in datetime string \"%s\"" ,
444- str );
454+ if (want_exc ) {
455+ PyErr_Format (PyExc_ValueError ,
456+ "Timezone hours offset out of range "
457+ "in datetime string \"%s\"" ,
458+ str );
459+ }
445460 goto error ;
446461 }
447462 } else if (sublen >= 1 && isdigit (substr [0 ])) {
@@ -466,10 +481,12 @@ int parse_iso_8601_datetime(const char *str, int len,
466481 substr += 2 ;
467482 sublen -= 2 ;
468483 if (offset_minute >= 60 ) {
469- PyErr_Format (PyExc_ValueError ,
470- "Timezone minutes offset out of range "
471- "in datetime string \"%s\"" ,
472- str );
484+ if (want_exc ) {
485+ PyErr_Format (PyExc_ValueError ,
486+ "Timezone minutes offset out of range "
487+ "in datetime string \"%s\"" ,
488+ str );
489+ }
473490 goto error ;
474491 }
475492 } else if (sublen >= 1 && isdigit (substr [0 ])) {
@@ -507,9 +524,11 @@ int parse_iso_8601_datetime(const char *str, int len,
507524 return 0 ;
508525
509526parse_error :
510- PyErr_Format (PyExc_ValueError ,
511- "Error parsing datetime string \"%s\" at position %d" , str ,
512- (int )(substr - str ));
527+ if (want_exc ) {
528+ PyErr_Format (PyExc_ValueError ,
529+ "Error parsing datetime string \"%s\" at position %d" , str ,
530+ (int )(substr - str ));
531+ }
513532 return -1 ;
514533
515534error :
0 commit comments