diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-26 23:37:22 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-08-26 23:37:22 +0000 |
commit | 25a48cd6f18b0e2dbb050b1dd4c441cc855c473e (patch) | |
tree | e6483ba1e961b50af3abbae91b595534d6691241 /usr.bin/calendar/day.c | |
parent | f96f166314dd54fc149d673c281b03c565d8c4d5 (diff) |
Make -t option use a date string like date(1).
Diffstat (limited to 'usr.bin/calendar/day.c')
-rw-r--r-- | usr.bin/calendar/day.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c index 6e06c97e1f6..29faf563d10 100644 --- a/usr.bin/calendar/day.c +++ b/usr.bin/calendar/day.c @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.1 1996/12/05 06:04:39 millert Exp $ */ +/* $OpenBSD: day.c,v 1.2 1997/08/26 23:37:21 millert Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -43,7 +43,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: day.c,v 1.1 1996/12/05 06:04:39 millert Exp $"; +static char rcsid[] = "$OpenBSD: day.c,v 1.2 1997/08/26 23:37:21 millert Exp $"; #endif #endif /* not lint */ @@ -173,13 +173,14 @@ settime(now) setnnames(); } -/* convert Day[/Month][/Year] into unix time (since 1970) - * Day: two digits, Month: two digits, Year: digits +/* convert [Year][Month]Day into unix time (since 1970) + * Year: two or four digits, Month: two digits, Day: two digits */ time_t Mktime (date) char *date; { time_t t; + char save; int len; struct tm tm; @@ -187,6 +188,8 @@ time_t Mktime (date) tp = localtime(&t); len = strlen(date); + if (len < 2) + return((time_t)-1); tm.tm_sec = 0; tm.tm_min = 0; tm.tm_hour = 0; @@ -195,20 +198,19 @@ time_t Mktime (date) tm.tm_mon = tp->tm_mon; tm.tm_year = tp->tm_year; + /* Day */ + tm.tm_mday = atoi(date + len - 2); - /* day */ - *(date+2) = NULL; - tm.tm_mday = atoi(date); - - /* month */ + /* Month */ if (len >= 4) { - *(date+5) = NULL; - tm.tm_mon = atoi(date+3) - 1; + *(date + len - 2) = '\0'; + tm.tm_mon = atoi(date + len - 4) - 1; } /* Year */ if (len >= 7) { - tm.tm_year = atoi(date+6); + *(date + len - 4) = '\0'; + tm.tm_year = atoi(date); /* tm_year up 1900 ... */ if (tm.tm_year > 1900) |