@@ -66,7 +66,7 @@ This file implements string parsing and creation for NumPy datetime.
66
66
*
67
67
* Returns 0 on success, -1 on failure.
68
68
*/
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 ,
70
70
npy_datetimestruct * out ,
71
71
int * out_local , int * out_tzoffset ) {
72
72
int year_leap = 0 ;
@@ -173,8 +173,10 @@ int parse_iso_8601_datetime(const char *str, int len,
173
173
goto parse_error ;
174
174
}
175
175
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
+ }
178
180
goto error ;
179
181
}
180
182
@@ -217,8 +219,10 @@ int parse_iso_8601_datetime(const char *str, int len,
217
219
}
218
220
if (out -> day < 1 ||
219
221
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
+ }
222
226
goto error ;
223
227
}
224
228
@@ -251,8 +255,11 @@ int parse_iso_8601_datetime(const char *str, int len,
251
255
++ substr ;
252
256
-- sublen ;
253
257
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
+ }
256
263
goto error ;
257
264
}
258
265
}
@@ -291,8 +298,11 @@ int parse_iso_8601_datetime(const char *str, int len,
291
298
++ substr ;
292
299
-- sublen ;
293
300
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
+ }
296
306
goto error ;
297
307
}
298
308
} else if (!has_hms_sep ) {
@@ -328,8 +338,11 @@ int parse_iso_8601_datetime(const char *str, int len,
328
338
++ substr ;
329
339
-- sublen ;
330
340
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
+ }
333
346
goto error ;
334
347
}
335
348
} else if (!has_hms_sep ) {
@@ -438,10 +451,12 @@ int parse_iso_8601_datetime(const char *str, int len,
438
451
substr += 2 ;
439
452
sublen -= 2 ;
440
453
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
+ }
445
460
goto error ;
446
461
}
447
462
} else if (sublen >= 1 && isdigit (substr [0 ])) {
@@ -466,10 +481,12 @@ int parse_iso_8601_datetime(const char *str, int len,
466
481
substr += 2 ;
467
482
sublen -= 2 ;
468
483
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
+ }
473
490
goto error ;
474
491
}
475
492
} else if (sublen >= 1 && isdigit (substr [0 ])) {
@@ -507,9 +524,11 @@ int parse_iso_8601_datetime(const char *str, int len,
507
524
return 0 ;
508
525
509
526
parse_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
+ }
513
532
return -1 ;
514
533
515
534
error :
0 commit comments