1997-12-21 12:11:13 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1998-05-06 06:51:42 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-08-27 23:15:48 +00:00
|
|
|
"$FreeBSD$";
|
1998-05-06 06:51:42 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1997-08-04 03:37:07 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "vary.h"
|
|
|
|
|
|
|
|
struct trans {
|
|
|
|
int val;
|
|
|
|
char *str;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct trans trans_mon[] = {
|
|
|
|
{ 1, "january" }, { 2, "february" }, { 3, "march" }, { 4, "april" },
|
2000-02-18 23:41:45 +00:00
|
|
|
{ 5, "may"}, { 6, "june" }, { 7, "july" }, { 8, "august" },
|
|
|
|
{ 9, "september" }, { 10, "october" }, { 11, "november" }, { 12, "december" },
|
1997-08-04 03:37:07 +00:00
|
|
|
{ -1, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct trans trans_wday[] = {
|
|
|
|
{ 0, "sunday" }, { 1, "monday" }, { 2, "tuesday" }, { 3, "wednesday" },
|
|
|
|
{ 4, "thursday" }, { 5, "friday" }, { 6, "saturday" },
|
|
|
|
{ -1, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static char digits[] = "0123456789";
|
2000-04-12 13:35:17 +00:00
|
|
|
static int adjhour(struct tm *, char, int, int);
|
2000-04-05 01:59:36 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
domktime(struct tm *t, char type)
|
|
|
|
{
|
2000-04-12 13:35:17 +00:00
|
|
|
time_t ret;
|
|
|
|
|
|
|
|
while ((ret = mktime(t)) == -1 && t->tm_year > 68 && t->tm_year < 138)
|
|
|
|
/* While mktime() fails, adjust by an hour */
|
|
|
|
adjhour(t, type == '-' ? type : '+', 1, 0);
|
2000-04-05 01:59:36 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
1997-08-04 03:37:07 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
trans(const struct trans t[], const char *arg)
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
|
|
|
|
for (f = 0; t[f].val != -1; f++)
|
1997-08-09 22:34:06 +00:00
|
|
|
if (!strncasecmp(t[f].str, arg, 3) ||
|
|
|
|
!strncasecmp(t[f].str, arg, strlen(t[f].str)))
|
1997-08-04 03:37:07 +00:00
|
|
|
return t[f].val;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct vary *
|
1997-08-09 22:34:06 +00:00
|
|
|
vary_append(struct vary *v, char *arg)
|
1997-08-04 03:37:07 +00:00
|
|
|
{
|
|
|
|
struct vary *result, **nextp;
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
result = v;
|
|
|
|
while (v->next)
|
|
|
|
v = v->next;
|
|
|
|
nextp = &v->next;
|
|
|
|
} else
|
|
|
|
nextp = &result;
|
|
|
|
|
|
|
|
*nextp = (struct vary *)malloc(sizeof(struct vary));
|
|
|
|
(*nextp)->arg = arg;
|
|
|
|
(*nextp)->next = NULL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mdays[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
|
|
|
|
|
static int
|
|
|
|
daysinmonth(const struct tm *t)
|
|
|
|
{
|
|
|
|
int year;
|
|
|
|
|
|
|
|
year = t->tm_year + 1900;
|
|
|
|
|
|
|
|
if (t->tm_mon == 1)
|
|
|
|
if (!(year % 400))
|
|
|
|
return 29;
|
|
|
|
else if (!(year % 100))
|
|
|
|
return 28;
|
|
|
|
else if (!(year % 4))
|
|
|
|
return 29;
|
|
|
|
else
|
|
|
|
return 28;
|
|
|
|
else if (t->tm_mon >= 0 && t->tm_mon < 12)
|
|
|
|
return mdays[t->tm_mon];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2000-04-12 13:35:17 +00:00
|
|
|
adjyear(struct tm *t, char type, int val, int mk)
|
1997-08-04 03:37:07 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case '+':
|
|
|
|
t->tm_year += val;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
t->tm_year -= val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
t->tm_year = val;
|
|
|
|
if (t->tm_year < 69)
|
|
|
|
t->tm_year += 100; /* as per date.c */
|
|
|
|
else if (t->tm_year > 1900)
|
|
|
|
t->tm_year -= 1900; /* struct tm holds years since 1900 */
|
|
|
|
break;
|
|
|
|
}
|
2000-04-12 13:35:17 +00:00
|
|
|
return !mk || domktime(t, type) != -1;
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-12 13:35:17 +00:00
|
|
|
adjmon(struct tm *t, char type, int val, int istext, int mk)
|
1997-08-04 03:37:07 +00:00
|
|
|
{
|
|
|
|
if (val < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case '+':
|
1999-04-25 21:13:34 +00:00
|
|
|
if (istext) {
|
1997-08-04 03:37:07 +00:00
|
|
|
if (val <= t->tm_mon)
|
|
|
|
val += 11 - t->tm_mon; /* early next year */
|
|
|
|
else
|
|
|
|
val -= t->tm_mon + 1; /* later this year */
|
1999-04-25 21:13:34 +00:00
|
|
|
}
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjyear(t, '+', (t->tm_mon + val) / 12, 0))
|
2000-04-05 01:59:36 +00:00
|
|
|
return 0;
|
|
|
|
val %= 12;
|
|
|
|
t->tm_mon += val;
|
|
|
|
if (t->tm_mon > 11)
|
|
|
|
t->tm_mon -= 12;
|
|
|
|
}
|
1997-08-04 03:37:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
1999-04-25 21:13:34 +00:00
|
|
|
if (istext) {
|
1997-08-04 03:37:07 +00:00
|
|
|
if (val-1 > t->tm_mon)
|
|
|
|
val = 13 - val + t->tm_mon; /* later last year */
|
|
|
|
else
|
|
|
|
val = t->tm_mon - val + 1; /* early this year */
|
1999-04-25 21:13:34 +00:00
|
|
|
}
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjyear(t, '-', val / 12, 0))
|
1997-08-04 03:37:07 +00:00
|
|
|
return 0;
|
2000-04-05 01:59:36 +00:00
|
|
|
val %= 12;
|
|
|
|
if (val > t->tm_mon) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjyear(t, '-', 1, 0))
|
2000-04-05 01:59:36 +00:00
|
|
|
return 0;
|
|
|
|
val -= 12;
|
|
|
|
}
|
|
|
|
t->tm_mon -= val;
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (val > 12 || val < 1)
|
|
|
|
return 0;
|
|
|
|
t->tm_mon = --val;
|
|
|
|
}
|
|
|
|
|
2000-04-12 13:35:17 +00:00
|
|
|
return !mk || domktime(t, type) != -1;
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-12 13:35:17 +00:00
|
|
|
adjday(struct tm *t, char type, int val, int mk)
|
1997-08-04 03:37:07 +00:00
|
|
|
{
|
|
|
|
int mdays;
|
2000-04-05 01:59:36 +00:00
|
|
|
|
1997-08-04 03:37:07 +00:00
|
|
|
switch (type) {
|
|
|
|
case '+':
|
|
|
|
while (val) {
|
|
|
|
mdays = daysinmonth(t);
|
|
|
|
if (val > mdays - t->tm_mday) {
|
|
|
|
val -= mdays - t->tm_mday + 1;
|
|
|
|
t->tm_mday = 1;
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjmon(t, '+', 1, 0, 0))
|
1997-08-04 03:37:07 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
t->tm_mday += val;
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
while (val)
|
|
|
|
if (val >= t->tm_mday) {
|
|
|
|
val -= t->tm_mday;
|
|
|
|
t->tm_mday = 1;
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjmon(t, '-', 1, 0, 0))
|
1997-08-04 03:37:07 +00:00
|
|
|
return 0;
|
|
|
|
t->tm_mday = daysinmonth(t);
|
|
|
|
} else {
|
|
|
|
t->tm_mday -= val;
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (val > 0 && val <= daysinmonth(t))
|
|
|
|
t->tm_mday = val;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-04-12 13:35:17 +00:00
|
|
|
return !mk || domktime(t, type) != -1;
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-12 13:35:17 +00:00
|
|
|
adjwday(struct tm *t, char type, int val, int istext, int mk)
|
1997-08-04 03:37:07 +00:00
|
|
|
{
|
|
|
|
if (val < 0)
|
|
|
|
return 0;
|
|
|
|
|
1997-08-09 22:34:06 +00:00
|
|
|
switch (type) {
|
1997-08-04 03:37:07 +00:00
|
|
|
case '+':
|
|
|
|
if (istext)
|
|
|
|
if (val < t->tm_wday)
|
|
|
|
val = 7 - t->tm_wday + val; /* early next week */
|
|
|
|
else
|
|
|
|
val -= t->tm_wday; /* later this week */
|
|
|
|
else
|
2000-04-05 01:59:36 +00:00
|
|
|
val *= 7; /* "-v+5w" == "5 weeks in the future" */
|
2000-04-12 13:35:17 +00:00
|
|
|
return !val || adjday(t, '+', val, 0);
|
1997-08-04 03:37:07 +00:00
|
|
|
case '-':
|
2000-04-05 01:59:36 +00:00
|
|
|
if (istext) {
|
1997-08-04 03:37:07 +00:00
|
|
|
if (val > t->tm_wday)
|
|
|
|
val = 7 - val + t->tm_wday; /* later last week */
|
|
|
|
else
|
|
|
|
val = t->tm_wday - val; /* early this week */
|
2000-04-05 01:59:36 +00:00
|
|
|
} else
|
|
|
|
val *= 7; /* "-v-5w" == "5 weeks ago" */
|
2000-04-12 13:35:17 +00:00
|
|
|
return !val || adjday(t, '-', val, 0);
|
1997-08-04 03:37:07 +00:00
|
|
|
default:
|
|
|
|
if (val < t->tm_wday)
|
2000-04-12 13:35:17 +00:00
|
|
|
return adjday(t, '-', t->tm_wday - val, 0);
|
1997-08-04 03:37:07 +00:00
|
|
|
else if (val > 6)
|
|
|
|
return 0;
|
|
|
|
else if (val > t->tm_wday)
|
2000-04-12 13:35:17 +00:00
|
|
|
return adjday(t, '+', val - t->tm_wday, 0);
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-12 13:35:17 +00:00
|
|
|
adjhour(struct tm *t, char type, int val, int mk)
|
1997-08-04 03:37:07 +00:00
|
|
|
{
|
1997-08-09 22:34:06 +00:00
|
|
|
if (val < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (type) {
|
1997-08-04 03:37:07 +00:00
|
|
|
case '+':
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
|
|
|
int days;
|
|
|
|
|
|
|
|
days = (t->tm_hour + val) / 24;
|
|
|
|
val %= 24;
|
|
|
|
t->tm_hour += val;
|
|
|
|
t->tm_hour %= 24;
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjday(t, '+', days, 0))
|
2000-04-05 01:59:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1997-08-09 22:34:06 +00:00
|
|
|
break;
|
|
|
|
|
1997-08-04 03:37:07 +00:00
|
|
|
case '-':
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
|
|
|
int days;
|
|
|
|
|
|
|
|
days = val / 24;
|
|
|
|
val %= 24;
|
|
|
|
if (val > t->tm_hour) {
|
|
|
|
days++;
|
|
|
|
val -= 24;
|
|
|
|
}
|
|
|
|
t->tm_hour -= val;
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjday(t, '-', days, 0))
|
1997-08-09 22:34:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-08-04 03:37:07 +00:00
|
|
|
default:
|
1997-08-09 22:34:06 +00:00
|
|
|
if (val > 23)
|
|
|
|
return 0;
|
|
|
|
t->tm_hour = val;
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
1997-08-09 22:34:06 +00:00
|
|
|
|
2000-04-12 13:35:17 +00:00
|
|
|
return !mk || domktime(t, type) != -1;
|
1997-08-09 22:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-12 13:35:17 +00:00
|
|
|
adjmin(struct tm *t, char type, int val, int mk)
|
1997-08-09 22:34:06 +00:00
|
|
|
{
|
|
|
|
if (val < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case '+':
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjhour(t, '+', (t->tm_min + val) / 60, 0))
|
2000-04-05 01:59:36 +00:00
|
|
|
return 0;
|
|
|
|
val %= 60;
|
|
|
|
t->tm_min += val;
|
|
|
|
if (t->tm_min > 59)
|
|
|
|
t->tm_min -= 60;
|
|
|
|
}
|
1997-08-09 22:34:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjhour(t, '-', val / 60, 0))
|
1997-08-09 22:34:06 +00:00
|
|
|
return 0;
|
2000-04-05 01:59:36 +00:00
|
|
|
val %= 60;
|
|
|
|
if (val > t->tm_min) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjhour(t, '-', 1, 0))
|
2000-04-05 01:59:36 +00:00
|
|
|
return 0;
|
|
|
|
val -= 60;
|
|
|
|
}
|
|
|
|
t->tm_min -= val;
|
1997-08-09 22:34:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (val > 59)
|
|
|
|
return 0;
|
|
|
|
t->tm_min = val;
|
|
|
|
}
|
|
|
|
|
2000-04-12 13:35:17 +00:00
|
|
|
return !mk || domktime(t, type) != -1;
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
|
|
|
|
1999-03-09 09:38:54 +00:00
|
|
|
static int
|
2000-04-12 13:35:17 +00:00
|
|
|
adjsec(struct tm *t, char type, int val, int mk)
|
1999-03-09 09:38:54 +00:00
|
|
|
{
|
|
|
|
if (val < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case '+':
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjmin(t, '+', (t->tm_sec + val) / 60, 0))
|
2000-04-05 01:59:36 +00:00
|
|
|
return 0;
|
|
|
|
val %= 60;
|
|
|
|
t->tm_sec += val;
|
|
|
|
if (t->tm_sec > 59)
|
|
|
|
t->tm_sec -= 60;
|
|
|
|
}
|
1999-03-09 09:38:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
2000-04-05 01:59:36 +00:00
|
|
|
if (val) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjmin(t, '-', val / 60, 0))
|
1999-03-09 09:38:54 +00:00
|
|
|
return 0;
|
2000-04-05 01:59:36 +00:00
|
|
|
val %= 60;
|
|
|
|
if (val > t->tm_sec) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjmin(t, '-', 1, 0))
|
2000-04-05 01:59:36 +00:00
|
|
|
return 0;
|
|
|
|
val -= 60;
|
|
|
|
}
|
|
|
|
t->tm_sec -= val;
|
1999-03-09 09:38:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (val > 59)
|
|
|
|
return 0;
|
|
|
|
t->tm_sec = val;
|
|
|
|
}
|
|
|
|
|
2000-04-12 13:35:17 +00:00
|
|
|
return !mk || domktime(t, type) != -1;
|
1999-03-09 09:38:54 +00:00
|
|
|
}
|
|
|
|
|
1997-08-04 03:37:07 +00:00
|
|
|
const struct vary *
|
|
|
|
vary_apply(const struct vary *v, struct tm *t)
|
|
|
|
{
|
1997-08-09 22:34:06 +00:00
|
|
|
char type;
|
|
|
|
char which;
|
|
|
|
char *arg;
|
|
|
|
int len;
|
|
|
|
int val;
|
|
|
|
|
1997-08-04 03:37:07 +00:00
|
|
|
for (; v; v = v->next) {
|
1997-08-09 22:34:06 +00:00
|
|
|
type = *v->arg;
|
|
|
|
arg = v->arg;
|
|
|
|
if (type == '+' || type == '-')
|
|
|
|
arg++;
|
|
|
|
else
|
|
|
|
type = '\0';
|
|
|
|
len = strlen(arg);
|
|
|
|
if (len < 2)
|
|
|
|
return v;
|
|
|
|
|
2000-04-12 13:35:17 +00:00
|
|
|
if (type == '\0')
|
|
|
|
t->tm_isdst = -1;
|
|
|
|
|
1997-08-09 22:34:06 +00:00
|
|
|
if (strspn(arg, digits) != len-1) {
|
|
|
|
val = trans(trans_wday, arg);
|
|
|
|
if (val != -1) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjwday(t, type, val, 1, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
} else {
|
|
|
|
val = trans(trans_mon, arg);
|
|
|
|
if (val != -1) {
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjmon(t, type, val, 1, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
} else
|
1997-08-04 03:37:07 +00:00
|
|
|
return v;
|
1997-08-09 22:34:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val = atoi(arg);
|
|
|
|
which = arg[len-1];
|
|
|
|
|
|
|
|
switch (which) {
|
1999-03-09 09:38:54 +00:00
|
|
|
case 'S':
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjsec(t, type, val, 1))
|
1999-03-09 09:38:54 +00:00
|
|
|
return v;
|
|
|
|
break;
|
1997-08-09 22:34:06 +00:00
|
|
|
case 'M':
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjmin(t, type, val, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
break;
|
|
|
|
case 'H':
|
2000-04-12 13:35:17 +00:00
|
|
|
if (!adjhour(t, type, val, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2000-04-12 13:35:17 +00:00
|
|
|
t->tm_isdst = -1;
|
|
|
|
if (!adjday(t, type, val, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
break;
|
|
|
|
case 'w':
|
2000-04-12 13:35:17 +00:00
|
|
|
t->tm_isdst = -1;
|
|
|
|
if (!adjwday(t, type, val, 0, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2000-04-12 13:35:17 +00:00
|
|
|
t->tm_isdst = -1;
|
|
|
|
if (!adjmon(t, type, val, 0, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
break;
|
|
|
|
case 'y':
|
2000-04-12 13:35:17 +00:00
|
|
|
t->tm_isdst = -1;
|
|
|
|
if (!adjyear(t, type, val, 1))
|
1997-08-09 22:34:06 +00:00
|
|
|
return v;
|
|
|
|
break;
|
|
|
|
default:
|
1997-08-04 03:37:07 +00:00
|
|
|
return v;
|
1997-08-09 22:34:06 +00:00
|
|
|
}
|
1997-08-04 03:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vary_destroy(struct vary *v)
|
|
|
|
{
|
|
|
|
struct vary *n;
|
|
|
|
|
|
|
|
while (v) {
|
|
|
|
n = v->next;
|
|
|
|
free(v);
|
|
|
|
v = n;
|
|
|
|
}
|
|
|
|
}
|