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
This commit is contained in:
parent
73fb8dcd42
commit
b6c989ff40
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=50411
@ -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
|
||||
|
@ -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 */
|
||||
|
||||
@ -271,52 +275,13 @@ expect(int desired)
|
||||
} /* expect */
|
||||
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user