@@ -405,9 +405,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
405405 return 0 ;
406406}
407407
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 )
409410{
410- time_t now ;
411411 struct tm now_tm ;
412412 struct tm * refuse_future ;
413413 long num2 , num3 ;
@@ -433,17 +433,18 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
433433 case '-' :
434434 case '/' :
435435 case '.' :
436- now = time (NULL );
436+ if (!now )
437+ now = time (NULL );
437438 refuse_future = NULL ;
438439 if (gmtime_r (& now , & now_tm ))
439440 refuse_future = & now_tm ;
440441
441442 if (num > 70 ) {
442443 /* yyyy-mm-dd? */
443- if (is_date (num , num2 , num3 , refuse_future , now , tm ))
444+ if (is_date (num , num2 , num3 , NULL , now , tm ))
444445 break ;
445446 /* yyyy-dd-mm? */
446- if (is_date (num , num3 , num2 , refuse_future , now , tm ))
447+ if (is_date (num , num3 , num2 , NULL , now , tm ))
447448 break ;
448449 }
449450 /* 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
513514 case '/' :
514515 case '-' :
515516 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 );
517518 if (match )
518519 return match ;
519520 }
@@ -1013,7 +1014,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
10131014 return end ;
10141015}
10151016
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 )
10171019{
10181020 char * end ;
10191021 unsigned long number = strtoul (date , & end , 10 );
@@ -1024,7 +1026,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
10241026 case '/' :
10251027 case '-' :
10261028 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 );
10281031 if (match )
10291032 return date + match ;
10301033 }
@@ -1087,7 +1090,7 @@ static unsigned long approxidate_str(const char *date,
10871090 date ++ ;
10881091 if (isdigit (c )) {
10891092 pending_number (& tm , & number );
1090- date = approxidate_digit (date - 1 , & tm , & number );
1093+ date = approxidate_digit (date - 1 , & tm , & number , time_sec );
10911094 touched = 1 ;
10921095 continue ;
10931096 }
0 commit comments