From 9787eba10e7af88493bba73d006f12564fa5cc35 Mon Sep 17 00:00:00 2001 From: sheldonh Date: Mon, 27 Mar 2000 09:32:23 +0000 Subject: Y2K fix. at(1) would die with 'garbled time' when assign_date() was pased a year > 99. This change fixes the conversion of 2-digit years into tm_year format. This change is differs from the OpenBSD fix because of differences in our assign_date(). PR: 15872 Reported by: "Crist J. Clark" Submitted by: "Sergey N. Voronkov" Obtained from: OpenBSD --- usr.bin/at/parsetime.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'usr.bin/at') diff --git a/usr.bin/at/parsetime.c b/usr.bin/at/parsetime.c index bc8f899..26e559e 100644 --- a/usr.bin/at/parsetime.c +++ b/usr.bin/at/parsetime.c @@ -399,27 +399,29 @@ tod(struct tm *tm) static void assign_date(struct tm *tm, long mday, long mon, long year) { - if (year > 99) { - if (year > 1899) - year -= 1900; - else - panic("garbled time"); - } else if (year != -1) { - struct tm *lt; - time_t now; - - time(&now); - lt = localtime(&now); - /* - * check if the specified year is in the next century. - * allow for one year of user error as many people will - * enter n - 1 at the start of year n. - */ - if (year < (lt->tm_year % 100) - 1) - year += 100; - /* adjust for the year 2000 and beyond */ - year += lt->tm_year - (lt->tm_year % 100); + /* + * Convert year into tm_year format (year - 1900). + * We may be given the year in 2 digit, 4 digit, or tm_year format. + */ + if (year != -1) { + if (year >= 1900) + year -= 1900; /* convert from 4 digit year */ + else if (year < 100) { + /* convert from 2 digit year */ + struct tm *lt; + time_t now; + + time(&now); + lt = localtime(&now); + + /* Convert to tm_year assuming current century */ + year += (lt->tm_year / 100) * 100; + + if (year == lt->tm_year - 1) year++; + else if (year < lt->tm_year) + year += 100; /* must be in next century */ + } } if (year < 0 && -- cgit v1.1