Extend time parsing to before 1970

It turns out that we are starting to have users that have logs that go
back that far. It won't be common, but let's get it right anyway.

NOTE! With us now supporting dates earlier in 1900, this also makes
"utc_mktime()" always add the "1900" to the year field.  That way we
avoid ever using the fairly ambiguous two-digit shorthand.

It didn't use to be all that ambiguous when we knew that any two-digit
number less than 70 had to be 2000+.  Now that we support going back to
earlier in the last centiry, that certainty is eroding.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2016-04-28 15:13:30 -07:00 committed by Dirk Hohndel
parent 1cf71a476b
commit 84166a4ee7
9 changed files with 69 additions and 34 deletions

View file

@ -126,7 +126,7 @@ static void update_date(timestamp_t *when, const char *line)
if (sscanf(line, "%04u-%02u-%02u", &yyyy, &mm, &dd) != 3)
return;
utc_mkdate(*when, &tm);
tm.tm_year = yyyy - 1900;
tm.tm_year = yyyy;
tm.tm_mon = mm - 1;
tm.tm_mday = dd;
*when = utc_mktime(&tm);
@ -1199,7 +1199,7 @@ static dive_trip_t *create_new_trip(int yyyy, int mm, int dd)
static bool validate_date(int yyyy, int mm, int dd)
{
return yyyy > 1970 && yyyy < 3000 &&
return yyyy > 1930 && yyyy < 3000 &&
mm > 0 && mm < 13 &&
dd > 0 && dd < 32;
}
@ -1308,7 +1308,7 @@ static int dive_directory(const char *root, const git_tree_entry *entry, const c
tm.tm_hour = h;
tm.tm_min = m;
tm.tm_sec = s;
tm.tm_year = yyyy - 1900;
tm.tm_year = yyyy;
tm.tm_mon = mm-1;
tm.tm_mday = dd;