Merge branch 'jk/approxidate-avoid-y-d-m-over-future-dates' into maint
* jk/approxidate-avoid-y-d-m-over-future-dates: approxidate: allow ISO-like dates far in the future pass TIME_DATE_NOW to approxidate future-check
This commit is contained in:
commit
9ea21fa89c
21
date.c
21
date.c
@ -405,9 +405,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm)
|
static int match_multi_number(unsigned long num, char c, const char *date,
|
||||||
|
char *end, struct tm *tm, time_t now)
|
||||||
{
|
{
|
||||||
time_t now;
|
|
||||||
struct tm now_tm;
|
struct tm now_tm;
|
||||||
struct tm *refuse_future;
|
struct tm *refuse_future;
|
||||||
long num2, num3;
|
long num2, num3;
|
||||||
@ -433,17 +433,18 @@ static int match_multi_number(unsigned long num, char c, const char *date, char
|
|||||||
case '-':
|
case '-':
|
||||||
case '/':
|
case '/':
|
||||||
case '.':
|
case '.':
|
||||||
now = time(NULL);
|
if (!now)
|
||||||
|
now = time(NULL);
|
||||||
refuse_future = NULL;
|
refuse_future = NULL;
|
||||||
if (gmtime_r(&now, &now_tm))
|
if (gmtime_r(&now, &now_tm))
|
||||||
refuse_future = &now_tm;
|
refuse_future = &now_tm;
|
||||||
|
|
||||||
if (num > 70) {
|
if (num > 70) {
|
||||||
/* yyyy-mm-dd? */
|
/* yyyy-mm-dd? */
|
||||||
if (is_date(num, num2, num3, refuse_future, now, tm))
|
if (is_date(num, num2, num3, NULL, now, tm))
|
||||||
break;
|
break;
|
||||||
/* yyyy-dd-mm? */
|
/* yyyy-dd-mm? */
|
||||||
if (is_date(num, num3, num2, refuse_future, now, tm))
|
if (is_date(num, num3, num2, NULL, now, tm))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Our eastern European friends say dd.mm.yy[yy]
|
/* 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
|
|||||||
case '/':
|
case '/':
|
||||||
case '-':
|
case '-':
|
||||||
if (isdigit(end[1])) {
|
if (isdigit(end[1])) {
|
||||||
int match = match_multi_number(num, *end, date, end, tm);
|
int match = match_multi_number(num, *end, date, end, tm, 0);
|
||||||
if (match)
|
if (match)
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
@ -1013,7 +1014,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
|
|||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
|
static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
|
||||||
|
time_t now)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
unsigned long number = strtoul(date, &end, 10);
|
unsigned long number = strtoul(date, &end, 10);
|
||||||
@ -1024,7 +1026,8 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num)
|
|||||||
case '/':
|
case '/':
|
||||||
case '-':
|
case '-':
|
||||||
if (isdigit(end[1])) {
|
if (isdigit(end[1])) {
|
||||||
int match = match_multi_number(number, *end, date, end, tm);
|
int match = match_multi_number(number, *end, date, end,
|
||||||
|
tm, now);
|
||||||
if (match)
|
if (match)
|
||||||
return date + match;
|
return date + match;
|
||||||
}
|
}
|
||||||
@ -1087,7 +1090,7 @@ static unsigned long approxidate_str(const char *date,
|
|||||||
date++;
|
date++;
|
||||||
if (isdigit(c)) {
|
if (isdigit(c)) {
|
||||||
pending_number(&tm, &number);
|
pending_number(&tm, &number);
|
||||||
date = approxidate_digit(date-1, &tm, &number);
|
date = approxidate_digit(date-1, &tm, &number, time_sec);
|
||||||
touched = 1;
|
touched = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -82,4 +82,7 @@ check_approxidate 'Jun 6, 5AM' '2009-06-06 05:00:00'
|
|||||||
check_approxidate '5AM Jun 6' '2009-06-06 05:00:00'
|
check_approxidate '5AM Jun 6' '2009-06-06 05:00:00'
|
||||||
check_approxidate '6AM, June 7, 2009' '2009-06-07 06:00:00'
|
check_approxidate '6AM, June 7, 2009' '2009-06-07 06:00:00'
|
||||||
|
|
||||||
|
check_approxidate '2008-12-01' '2008-12-01 19:20:00'
|
||||||
|
check_approxidate '2009-12-01' '2009-12-01 19:20:00'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user