@@ -100,7 +100,6 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
100
100
const char * substr ;
101
101
int sublen ;
102
102
NPY_DATETIMEUNIT bestunit = NPY_FR_GENERIC ;
103
- printf ("format len: %d" , format_len );
104
103
105
104
/* If year-month-day are separated by a valid separator,
106
105
* months/days without leading zeroes will be parsed
@@ -170,7 +169,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
170
169
if (out_local != NULL ) {
171
170
* out_local = 0 ;
172
171
}
173
- if (* format ) {
172
+ if (format_len ) {
174
173
goto parse_error ;
175
174
}
176
175
bestunit = NPY_FR_Y ;
@@ -227,7 +226,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
227
226
if (!has_ymd_sep ) {
228
227
goto parse_error ;
229
228
}
230
- if (* format ) {
229
+ if (format_len ) {
231
230
goto parse_error ;
232
231
}
233
232
if (out_local != NULL ) {
@@ -278,7 +277,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
278
277
if (out_local != NULL ) {
279
278
* out_local = 0 ;
280
279
}
281
- if (* format ) {
280
+ if (format_len ) {
282
281
goto parse_error ;
283
282
}
284
283
bestunit = NPY_FR_D ;
@@ -323,7 +322,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
323
322
if (!hour_was_2_digits ) {
324
323
goto parse_error ;
325
324
}
326
- if (* format ) {
325
+ if (format_len ) {
327
326
goto parse_error ;
328
327
}
329
328
bestunit = NPY_FR_h ;
@@ -372,7 +371,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
372
371
373
372
if (sublen == 0 ) {
374
373
bestunit = NPY_FR_m ;
375
- if (* format ) {
374
+ if (format_len ) {
376
375
goto parse_error ;
377
376
}
378
377
goto finish ;
@@ -494,15 +493,21 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
494
493
while (sublen > 0 && isspace (* substr )) {
495
494
++ substr ;
496
495
-- sublen ;
496
+ FORMAT_STARTSWITH (' ' );
497
497
}
498
498
499
499
if (sublen == 0 ) {
500
500
// Unlike NumPy, treating no time zone as naive
501
+ if (format_len > 0 ){
502
+ goto parse_error ;
503
+ }
501
504
goto finish ;
502
505
}
503
506
504
507
/* UTC specifier */
505
508
if (* substr == 'Z' ) {
509
+ FORMAT_STARTSWITH ('Z' );
510
+
506
511
/* "Z" should be equivalent to tz offset "+00:00" */
507
512
if (out_local != NULL ) {
508
513
* out_local = 1 ;
@@ -513,12 +518,16 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
513
518
}
514
519
515
520
if (sublen == 1 ) {
521
+ if (format_len > 0 ){
522
+ goto parse_error ;
523
+ }
516
524
goto finish ;
517
525
} else {
518
526
++ substr ;
519
527
-- sublen ;
520
528
}
521
529
} else if (* substr == '-' || * substr == '+' ) {
530
+ FORMAT_STARTSWITH ('z' );
522
531
/* Time zone offset */
523
532
int offset_neg = 0 , offset_hour = 0 , offset_minute = 0 ;
524
533
@@ -602,9 +611,10 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
602
611
while (sublen > 0 && isspace (* substr )) {
603
612
++ substr ;
604
613
-- sublen ;
614
+ FORMAT_STARTSWITH (' ' );
605
615
}
606
616
607
- if (sublen != 0 ) {
617
+ if (( sublen != 0 ) || ( format_len != 0 ) ) {
608
618
goto parse_error ;
609
619
}
610
620
0 commit comments