From fc7337e0f6e7f7da71a39cb872d02ca58f888f17 Mon Sep 17 00:00:00 2001 From: nsayer Date: Thu, 26 Aug 1999 16:18:38 +0000 Subject: 1. Add support for months and years in relative time spec (now + 1 year) 2. Rip out dateadd() and re-do the plus operator handler to use mktime() instead (per wollman). Reviewed by: wollman --- usr.bin/at/at.man | 6 ++-- usr.bin/at/parsetime.c | 81 +++++++++++++++++++------------------------------- 2 files changed, 35 insertions(+), 52 deletions(-) diff --git a/usr.bin/at/at.man b/usr.bin/at/at.man index ceee348..02c7930 100644 --- a/usr.bin/at/at.man +++ b/usr.bin/at/at.man @@ -1,4 +1,4 @@ -.\" $Id: at.man,v 1.9 1999/02/15 08:34:06 fenner Exp $ +.\" $Id: at.man,v 1.10 1999/08/15 08:25:13 mpp Exp $ .Dd April 12, 1995 .Dt "AT" 1 .Os FreeBSD 2.1 @@ -94,8 +94,10 @@ where the time-units can be .Nm minutes , .Nm hours , .Nm days , +.Nm weeks , +.Nm months or -.Nm weeks +.Nm years and you can tell .Nm at to run the job today by suffixing the time with diff --git a/usr.bin/at/parsetime.c b/usr.bin/at/parsetime.c index 8cde1dc..dd1fd90 100644 --- a/usr.bin/at/parsetime.c +++ b/usr.bin/at/parsetime.c @@ -60,7 +60,7 @@ enum { /* symbols */ MIDNIGHT, NOON, TEATIME, PM, AM, TOMORROW, TODAY, NOW, - MINUTES, HOURS, DAYS, WEEKS, + MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS, NUMBER, PLUS, DOT, SLASH, ID, JUNK, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, @@ -91,6 +91,10 @@ struct { { "days", DAYS,1 }, /* (pluralized) */ { "week", WEEKS,0 }, /* week ... */ { "weeks", WEEKS,1 }, /* (pluralized) */ + { "month", MONTHS,0 }, /* month ... */ + { "months", MONTHS,1 }, /* (pluralized) */ + { "year", YEARS,0 }, /* year ... */ + { "years", YEARS,1 }, /* (pluralized) */ { "jan", JAN,0 }, { "feb", FEB,0 }, { "mar", MAR,0 }, @@ -144,7 +148,7 @@ static int sc_tokid; /* scanner - token id */ static int sc_tokplur; /* scanner - is token plural? */ static const char rcsid[] = - "$Id: parsetime.c,v 1.15 1998/08/30 17:33:05 steve Exp $"; + "$Id: parsetime.c,v 1.16 1998/12/06 07:42:09 archie Exp $"; /* Local functions */ @@ -272,51 +276,12 @@ expect(int desired) /* - * dateadd() adds a number of minutes to a date. It is extraordinarily - * stupid regarding day-of-month overflow, and will most likely not - * work properly - */ -static void -dateadd(int minutes, struct tm *tm) -{ - /* increment days */ - - while (minutes > 24*60) { - minutes -= 24*60; - tm->tm_mday++; - } - - /* increment hours */ - while (minutes > 60) { - minutes -= 60; - tm->tm_hour++; - if (tm->tm_hour > 23) { - tm->tm_mday++; - tm->tm_hour = 0; - } - } - - /* increment minutes */ - tm->tm_min += minutes; - - if (tm->tm_min > 59) { - tm->tm_hour++; - tm->tm_min -= 60; - - if (tm->tm_hour > 23) { - tm->tm_mday++; - tm->tm_hour = 0; - } - } -} /* dateadd */ - - -/* * plus() parses a now + time * - * at [NOW] PLUS NUMBER [MINUTES|HOURS|DAYS|WEEKS] + * at [NOW] PLUS NUMBER [MINUTES|HOURS|DAYS|WEEKS|MONTHS|YEARS] * */ + static void plus(struct tm *tm) { @@ -329,19 +294,35 @@ plus(struct tm *tm) expectplur = (delay != 1) ? 1 : 0; switch (token()) { + case YEARS: + tm->tm_year += delay; + break; + case MONTHS: + tm->tm_mon += delay; + break; case WEEKS: delay *= 7; case DAYS: - delay *= 24; + tm->tm_mday += delay; + break; case HOURS: - delay *= 60; + tm->tm_hour += delay; + break; case MINUTES: - if (expectplur != sc_tokplur) - warnx("pluralization is wrong"); - dateadd(delay, tm); - return; + tm->tm_min += delay; + break; + default: + plonk(sc_tokid); + break; } - plonk(sc_tokid); + + if (expectplur != sc_tokplur) + warnx("pluralization is wrong"); + + tm->tm_isdst = -1; + if (mktime(tm) < 0) + plonk(sc_tokid); + } /* plus */ -- cgit v1.1