calendarspec: parse 'quarterly' and 'semi-annually' as shortcuts

This commit is contained in:
Lennart Poettering
2014-10-27 18:09:26 +01:00
parent a2a85a22b3
commit dbfd41e2df
3 changed files with 68 additions and 8 deletions
+56 -3
View File
@@ -474,7 +474,7 @@ static int const_chain(int value, CalendarComponent **c) {
cc->value = value;
cc->repeat = 0;
cc->next = NULL;
cc->next = *c;
*c = cc;
@@ -693,8 +693,10 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
if (r < 0)
goto fail;
} else if (strcaseeq(p, "annually") || strcaseeq(p, "yearly")
|| strcaseeq(p, "anually") /* backwards compatibility */ ) {
} else if (strcaseeq(p, "annually") ||
strcaseeq(p, "yearly") ||
strcaseeq(p, "anually") /* backwards compatibility */ ) {
r = const_chain(1, &c->month);
if (r < 0)
goto fail;
@@ -725,6 +727,57 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
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)
+4
View File
@@ -77,6 +77,10 @@ int main(int argc, char* argv[]) {
test_one("daily", "*-*-* 00:00:00");
test_one("monthly", "*-*-01 00:00:00");
test_one("weekly", "Mon *-*-* 00:00:00");
test_one("minutely", "*-*-* *:*:00");
test_one("quarterly", "*-01,04,07,10-01 00:00:00");
test_one("semi-annually", "*-01,07-01 00:00:00");
test_one("annually", "*-01-01 00:00:00");
test_one("*:2/3", "*-*-* *:02/3:00");
assert_se(calendar_spec_from_string("test", &c) < 0);