@@ -402,6 +402,15 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
402
402
return end - date ;
403
403
}
404
404
405
+ /* Have we filled in any part of the time/date yet? */
406
+ static inline int nodate (struct tm * tm )
407
+ {
408
+ return tm -> tm_year < 0 &&
409
+ tm -> tm_mon < 0 &&
410
+ tm -> tm_mday < 0 &&
411
+ !(tm -> tm_hour | tm -> tm_min | tm -> tm_sec );
412
+ }
413
+
405
414
/*
406
415
* We've seen a digit. Time? Year? Date?
407
416
*/
@@ -418,7 +427,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
418
427
* more than 8 digits. This is because we don't want to rule out
419
428
* numbers like 20070606 as a YYYYMMDD date.
420
429
*/
421
- if (num >= 100000000 ) {
430
+ if (num >= 100000000 && nodate ( tm ) ) {
422
431
time_t time = num ;
423
432
if (gmtime_r (& time , tm )) {
424
433
* tm_gmt = 1 ;
@@ -462,6 +471,13 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
462
471
return n ;
463
472
}
464
473
474
+ /*
475
+ * Ignore lots of numerals. We took care of 4-digit years above.
476
+ * Days or months must be one or two digits.
477
+ */
478
+ if (n > 2 )
479
+ return n ;
480
+
465
481
/*
466
482
* NOTE! We will give precedence to day-of-month over month or
467
483
* year numbers in the 1-12 range. So 05 is always "mday 5",
@@ -488,10 +504,6 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
488
504
489
505
if (num > 0 && num < 32 ) {
490
506
tm -> tm_mday = num ;
491
- } else if (num > 1900 ) {
492
- tm -> tm_year = num - 1900 ;
493
- } else if (num > 70 ) {
494
- tm -> tm_year = num ;
495
507
} else if (num > 0 && num < 13 ) {
496
508
tm -> tm_mon = num - 1 ;
497
509
}
@@ -823,7 +835,9 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
823
835
}
824
836
}
825
837
826
- * num = number ;
838
+ /* Accept zero-padding only for small numbers ("Dec 02", never "Dec 0002") */
839
+ if (date [0 ] != '0' || end - date <= 2 )
840
+ * num = number ;
827
841
return end ;
828
842
}
829
843
0 commit comments