diff options
author | Alex Feldman <alex@cvs.openbsd.org> | 1999-03-21 04:04:43 +0000 |
---|---|---|
committer | Alex Feldman <alex@cvs.openbsd.org> | 1999-03-21 04:04:43 +0000 |
commit | 9f2c8a42df759501915347343d5170a808de59bc (patch) | |
tree | 104cab57d89c24f160a607be22db1722901ccc58 /usr.bin | |
parent | 4650d473b33558ca5ff984df9c7d9ac0093acff9 (diff) |
PR 778: Handle 2-digit year values post-Y2K. Improvements to PR 778
provided by pjanzen.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/at/at.1 | 7 | ||||
-rw-r--r-- | usr.bin/at/parsetime.c | 21 |
2 files changed, 22 insertions, 6 deletions
diff --git a/usr.bin/at/at.1 b/usr.bin/at/at.1 index 54b89042b09..f3d4befef87 100644 --- a/usr.bin/at/at.1 +++ b/usr.bin/at/at.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: at.1,v 1.8 1998/11/04 22:36:40 aaron Exp $ +.\" $OpenBSD: at.1,v 1.9 1999/03/21 04:04:41 alex Exp $ .\" $FreeBSD: at.man,v 1.6 1997/02/22 19:54:05 peter Exp $ .Dd April 12, 1995 .Dt AT 1 @@ -81,6 +81,11 @@ or giving a date of the form .Ar MM/DD/YY or .Ar DD.MM.YY . +The year may be given as two digits or four digits. +If the year is given as two digits, it is taken to occur as soon as +possible in the future, which may be in the next century -- +unless it's last year, in which case it's considered to be +a typo. The specification of a date must follow the specification of the time of day. You can also give times like diff --git a/usr.bin/at/parsetime.c b/usr.bin/at/parsetime.c index fc3c930f21a..69cea695165 100644 --- a/usr.bin/at/parsetime.c +++ b/usr.bin/at/parsetime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parsetime.c,v 1.7 1998/07/10 07:07:04 deraadt Exp $ */ +/* $OpenBSD: parsetime.c,v 1.8 1999/03/21 04:04:42 alex Exp $ */ /* $NetBSD: parsetime.c,v 1.3 1995/03/25 18:13:36 glass Exp $ */ /* @@ -44,6 +44,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <tzfile.h> #include <unistd.h> #include <ctype.h> #include <err.h> @@ -150,7 +151,7 @@ static int sc_tokid; /* scanner - token id */ static int sc_tokplur; /* scanner - is token plural? */ #ifndef lint -static char rcsid[] = "$OpenBSD: parsetime.c,v 1.7 1998/07/10 07:07:04 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: parsetime.c,v 1.8 1999/03/21 04:04:42 alex Exp $"; #endif /* Local functions */ @@ -443,10 +444,20 @@ assign_date(tm, mday, mon, year) int mday, mon, year; { if (year > 99) { - if (year > 1899) - year -= 1900; + if (year >= TM_YEAR_BASE) + year -= TM_YEAR_BASE; else panic("garbled time"); + } else if (year != -1) { + /* + * 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 < tm->tm_year % 100 - 1) + year += 100; + /* adjust for the year 2000 and beyond */ + year += tm->tm_year - (tm->tm_year % 100); } if (year < 0 && @@ -556,7 +567,7 @@ month(tm) } } else if (tlen == 6 || tlen == 8) { if (tlen == 8) { - year = (mon % 10000) - 1900; + year = (mon % 10000) - TM_YEAR_BASE; mon /= 10000; } else { year = mon % 100; |