summaryrefslogtreecommitdiff
path: root/usr.bin/at/parsetime.c
diff options
context:
space:
mode:
authorAlex Feldman <alex@cvs.openbsd.org>1999-03-21 04:04:43 +0000
committerAlex Feldman <alex@cvs.openbsd.org>1999-03-21 04:04:43 +0000
commit9f2c8a42df759501915347343d5170a808de59bc (patch)
tree104cab57d89c24f160a607be22db1722901ccc58 /usr.bin/at/parsetime.c
parent4650d473b33558ca5ff984df9c7d9ac0093acff9 (diff)
PR 778: Handle 2-digit year values post-Y2K. Improvements to PR 778
provided by pjanzen.
Diffstat (limited to 'usr.bin/at/parsetime.c')
-rw-r--r--usr.bin/at/parsetime.c21
1 files changed, 16 insertions, 5 deletions
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;