Skip to content

Commit 8cdb200

Browse files
author
Marco Gorelli
committed
wip
1 parent 0eaa6da commit 8cdb200

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

pandas/_libs/tslibs/src/datetime/np_datetime_strings.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
100100
const char *substr;
101101
int sublen;
102102
NPY_DATETIMEUNIT bestunit = NPY_FR_GENERIC;
103-
printf("format len: %d", format_len);
104103

105104
/* If year-month-day are separated by a valid separator,
106105
* 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,
170169
if (out_local != NULL) {
171170
*out_local = 0;
172171
}
173-
if (*format) {
172+
if (format_len) {
174173
goto parse_error;
175174
}
176175
bestunit = NPY_FR_Y;
@@ -227,7 +226,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
227226
if (!has_ymd_sep) {
228227
goto parse_error;
229228
}
230-
if (*format) {
229+
if (format_len) {
231230
goto parse_error;
232231
}
233232
if (out_local != NULL) {
@@ -278,7 +277,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
278277
if (out_local != NULL) {
279278
*out_local = 0;
280279
}
281-
if (*format) {
280+
if (format_len) {
282281
goto parse_error;
283282
}
284283
bestunit = NPY_FR_D;
@@ -323,7 +322,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
323322
if (!hour_was_2_digits) {
324323
goto parse_error;
325324
}
326-
if (*format) {
325+
if (format_len) {
327326
goto parse_error;
328327
}
329328
bestunit = NPY_FR_h;
@@ -372,7 +371,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
372371

373372
if (sublen == 0) {
374373
bestunit = NPY_FR_m;
375-
if (*format) {
374+
if (format_len) {
376375
goto parse_error;
377376
}
378377
goto finish;
@@ -494,15 +493,21 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
494493
while (sublen > 0 && isspace(*substr)) {
495494
++substr;
496495
--sublen;
496+
FORMAT_STARTSWITH(' ');
497497
}
498498

499499
if (sublen == 0) {
500500
// Unlike NumPy, treating no time zone as naive
501+
if (format_len > 0){
502+
goto parse_error;
503+
}
501504
goto finish;
502505
}
503506

504507
/* UTC specifier */
505508
if (*substr == 'Z') {
509+
FORMAT_STARTSWITH('Z');
510+
506511
/* "Z" should be equivalent to tz offset "+00:00" */
507512
if (out_local != NULL) {
508513
*out_local = 1;
@@ -513,12 +518,16 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
513518
}
514519

515520
if (sublen == 1) {
521+
if (format_len > 0){
522+
goto parse_error;
523+
}
516524
goto finish;
517525
} else {
518526
++substr;
519527
--sublen;
520528
}
521529
} else if (*substr == '-' || *substr == '+') {
530+
FORMAT_STARTSWITH('z');
522531
/* Time zone offset */
523532
int offset_neg = 0, offset_hour = 0, offset_minute = 0;
524533

@@ -602,9 +611,10 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
602611
while (sublen > 0 && isspace(*substr)) {
603612
++substr;
604613
--sublen;
614+
FORMAT_STARTSWITH(' ');
605615
}
606616

607-
if (sublen != 0) {
617+
if ((sublen != 0) || (format_len != 0)) {
608618
goto parse_error;
609619
}
610620

0 commit comments

Comments
 (0)