@@ -405,9 +405,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
405
405
return 0 ;
406
406
}
407
407
408
- static int match_multi_number (unsigned long num , char c , const char * date , char * end , struct tm * tm )
408
+ static int match_multi_number (unsigned long num , char c , const char * date ,
409
+ char * end , struct tm * tm , time_t now )
409
410
{
410
- time_t now ;
411
411
struct tm now_tm ;
412
412
struct tm * refuse_future ;
413
413
long num2 , num3 ;
@@ -433,17 +433,18 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
433
433
case '-' :
434
434
case '/' :
435
435
case '.' :
436
- now = time (NULL );
436
+ if (!now )
437
+ now = time (NULL );
437
438
refuse_future = NULL ;
438
439
if (gmtime_r (& now , & now_tm ))
439
440
refuse_future = & now_tm ;
440
441
441
442
if (num > 70 ) {
442
443
/* yyyy-mm-dd? */
443
- if (is_date (num , num2 , num3 , refuse_future , now , tm ))
444
+ if (is_date (num , num2 , num3 , NULL , now , tm ))
444
445
break ;
445
446
/* yyyy-dd-mm? */
446
- if (is_date (num , num3 , num2 , refuse_future , now , tm ))
447
+ if (is_date (num , num3 , num2 , NULL , now , tm ))
447
448
break ;
448
449
}
449
450
/* Our eastern European friends say dd.mm.yy[yy]
@@ -513,7 +514,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
513
514
case '/' :
514
515
case '-' :
515
516
if (isdigit (end [1 ])) {
516
- int match = match_multi_number (num , * end , date , end , tm );
517
+ int match = match_multi_number (num , * end , date , end , tm , 0 );
517
518
if (match )
518
519
return match ;
519
520
}
@@ -1013,7 +1014,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
1013
1014
return end ;
1014
1015
}
1015
1016
1016
- static const char * approxidate_digit (const char * date , struct tm * tm , int * num )
1017
+ static const char * approxidate_digit (const char * date , struct tm * tm , int * num ,
1018
+ time_t now )
1017
1019
{
1018
1020
char * end ;
1019
1021
unsigned long number = strtoul (date , & end , 10 );
@@ -1024,7 +1026,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
1024
1026
case '/' :
1025
1027
case '-' :
1026
1028
if (isdigit (end [1 ])) {
1027
- int match = match_multi_number (number , * end , date , end , tm );
1029
+ int match = match_multi_number (number , * end , date , end ,
1030
+ tm , now );
1028
1031
if (match )
1029
1032
return date + match ;
1030
1033
}
@@ -1087,7 +1090,7 @@ static unsigned long approxidate_str(const char *date,
1087
1090
date ++ ;
1088
1091
if (isdigit (c )) {
1089
1092
pending_number (& tm , & number );
1090
- date = approxidate_digit (date - 1 , & tm , & number );
1093
+ date = approxidate_digit (date - 1 , & tm , & number , time_sec );
1091
1094
touched = 1 ;
1092
1095
continue ;
1093
1096
}
0 commit comments