diff options
author | sheldonh <sheldonh@FreeBSD.org> | 2000-03-27 09:32:23 +0000 |
---|---|---|
committer | sheldonh <sheldonh@FreeBSD.org> | 2000-03-27 09:32:23 +0000 |
commit | 9787eba10e7af88493bba73d006f12564fa5cc35 (patch) | |
tree | 388f46ce144ba9cd2189bc4503de041bc7ef0cba /usr.bin/at/parsetime.c | |
parent | 37935ccdc33582b54c89e55b7faf54951dfff62e (diff) | |
download | FreeBSD-src-9787eba10e7af88493bba73d006f12564fa5cc35.zip FreeBSD-src-9787eba10e7af88493bba73d006f12564fa5cc35.tar.gz |
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" <cjclark@home.com>
Submitted by: "Sergey N. Voronkov" <serg@dor.zaural.ru>
Obtained from: OpenBSD
Diffstat (limited to 'usr.bin/at/parsetime.c')
-rw-r--r-- | usr.bin/at/parsetime.c | 42 |
1 files changed, 22 insertions, 20 deletions
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 && |