diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2008-10-09 10:23:55 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2008-10-09 10:23:55 -0700 |
commit | 78a935d48b28ebf5b1af348d7e57763f2955afd1 (patch) | |
tree | 804d3b2ec5dd9dcb2ff7ecadd3b646131292f434 | |
parent | a3c76f2858b1ceae5b70b7ee69d2663143dcce49 (diff) | |
parent | 9f2b6d2936a7c4bb3155de8efec7b10869ca935e (diff) | |
download | git-78a935d48b28ebf5b1af348d7e57763f2955afd1.tar.gz git-78a935d48b28ebf5b1af348d7e57763f2955afd1.tar.xz |
Merge branch 'lt/time-reject-fractional-seconds'
* lt/time-reject-fractional-seconds:
date/time: do not get confused by fractional seconds
-rw-r--r-- | date.c | 26 |
1 files changed, 20 insertions, 6 deletions
@@ -402,6 +402,15 @@ static int match_multi_number(unsigned long num, char c, const char *date, char return end - date; } +/* Have we filled in any part of the time/date yet? */ +static inline int nodate(struct tm *tm) +{ + return tm->tm_year < 0 && + tm->tm_mon < 0 && + tm->tm_mday < 0 && + !(tm->tm_hour | tm->tm_min | tm->tm_sec); +} + /* * We've seen a digit. Time? Year? Date? */ @@ -418,7 +427,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt * more than 8 digits. This is because we don't want to rule out * numbers like 20070606 as a YYYYMMDD date. */ - if (num >= 100000000) { + if (num >= 100000000 && nodate(tm)) { time_t time = num; if (gmtime_r(&time, tm)) { *tm_gmt = 1; @@ -463,6 +472,13 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt } /* + * Ignore lots of numerals. We took care of 4-digit years above. + * Days or months must be one or two digits. + */ + if (n > 2) + return n; + + /* * NOTE! We will give precedence to day-of-month over month or * year numbers in the 1-12 range. So 05 is always "mday 5", * unless we already have a mday.. @@ -488,10 +504,6 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt if (num > 0 && num < 32) { tm->tm_mday = num; - } else if (num > 1900) { - tm->tm_year = num - 1900; - } else if (num > 70) { - tm->tm_year = num; } else if (num > 0 && num < 13) { tm->tm_mon = num-1; } @@ -823,7 +835,9 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num) } } - *num = number; + /* Accept zero-padding only for small numbers ("Dec 02", never "Dec 0002") */ + if (date[0] != '0' || end - date <= 2) + *num = number; return end; } |