#include "calendarspec.h"
+#define BITS_WEEKDAYS 127
+
static void free_chain(CalendarComponent *c) {
CalendarComponent *n;
}
void calendar_spec_free(CalendarSpec *c) {
- assert(c);
+
+ if (!c)
+ return;
free_chain(c->year);
free_chain(c->month);
int calendar_spec_normalize(CalendarSpec *c) {
assert(c);
- if (c->weekdays_bits <= 0 || c->weekdays_bits >= 127)
+ if (c->weekdays_bits <= 0 || c->weekdays_bits >= BITS_WEEKDAYS)
c->weekdays_bits = -1;
fix_year(c->year);
_pure_ bool calendar_spec_valid(CalendarSpec *c) {
assert(c);
- if (c->weekdays_bits > 127)
+ if (c->weekdays_bits > BITS_WEEKDAYS)
return false;
if (!chain_valid(c->year, 1970, 2199))
assert(f);
assert(c);
- assert(c->weekdays_bits > 0 && c->weekdays_bits <= 127);
+ assert(c->weekdays_bits > 0 && c->weekdays_bits <= BITS_WEEKDAYS);
for (x = 0, l = -1; x < (int) ELEMENTSOF(days); x++) {
if (!f)
return -ENOMEM;
- if (c->weekdays_bits > 0 && c->weekdays_bits <= 127) {
+ if (c->weekdays_bits > 0 && c->weekdays_bits <= BITS_WEEKDAYS) {
format_weekdays(f, c);
fputc(' ', f);
}
cc->value = value;
cc->repeat = 0;
- cc->next = NULL;
+ cc->next = *c;
*c = cc;
if (!c)
return -ENOMEM;
- if (strcaseeq(p, "hourly")) {
+ if (strcaseeq(p, "minutely")) {
+ r = const_chain(0, &c->second);
+ if (r < 0)
+ goto fail;
+
+ } else if (strcaseeq(p, "hourly")) {
r = const_chain(0, &c->minute);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
+ } else if (strcaseeq(p, "annually") ||
+ strcaseeq(p, "yearly") ||
+ strcaseeq(p, "anually") /* backwards compatibility */ ) {
+
+ r = const_chain(1, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(1, &c->day);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->hour);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->minute);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->second);
+ if (r < 0)
+ goto fail;
+
} else if (strcaseeq(p, "weekly")) {
c->weekdays_bits = 1;
if (r < 0)
goto fail;
+ } else if (strcaseeq(p, "quarterly")) {
+
+ r = const_chain(1, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(4, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(7, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(10, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(1, &c->day);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->hour);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->minute);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->second);
+ if (r < 0)
+ goto fail;
+
+ } else if (strcaseeq(p, "biannually") ||
+ strcaseeq(p, "bi-annually") ||
+ strcaseeq(p, "semiannually") ||
+ strcaseeq(p, "semi-annually")) {
+
+ r = const_chain(1, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(7, &c->month);
+ if (r < 0)
+ goto fail;
+ r = const_chain(1, &c->day);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->hour);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->minute);
+ if (r < 0)
+ goto fail;
+ r = const_chain(0, &c->second);
+ if (r < 0)
+ goto fail;
+
} else {
r = parse_weekdays(&p, c);
if (r < 0)
struct tm t;
int k;
- if (weekdays_bits < 0 || weekdays_bits >= 127)
+ if (weekdays_bits < 0 || weekdays_bits >= BITS_WEEKDAYS)
return true;
t = *tm;
if (t == (time_t) -1)
return -EINVAL;
-
*next = (usec_t) t * USEC_PER_SEC;
return 0;
}