Skip to content

Commit dbfd41e

Browse files
committed
calendarspec: parse 'quarterly' and 'semi-annually' as shortcuts
1 parent a2a85a2 commit dbfd41e

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

man/systemd.time.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,18 @@
245245
<literal>minutely</literal>,
246246
<literal>hourly</literal>, <literal>daily</literal>,
247247
<literal>monthly</literal>, <literal>weekly</literal>,
248-
and <literal>yearly</literal> or
249-
<literal>annually</literal> may be used as calendar
250-
events which refer to
248+
<literal>yearly</literal>,
249+
<literal>quarterly</literal>,
250+
<literal>semiannually</literal> may be used as
251+
calendar events which refer to
251252
<literal>*-*-* *:*:00</literal>,
252253
<literal>*-*-* *:00:00</literal>,
253254
<literal>*-*-* 00:00:00</literal>,
254255
<literal>*-*-01 00:00:00</literal>,
255-
<literal>Mon *-*-* 00:00:00</literal>, and
256-
<literal>*-01-01 00:00:00</literal> respectively.
256+
<literal>Mon *-*-* 00:00:00</literal>,
257+
<literal>*-01-01 00:00:00</literal>,
258+
<literal>*-01,04,07,10-01 00:00:0</literal> and
259+
<literal>*-01,07-01 00:00:00</literal> respectively.
257260
</para>
258261

259262
<para>Examples for valid timestamps and their

src/shared/calendarspec.c

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int const_chain(int value, CalendarComponent **c) {
474474

475475
cc->value = value;
476476
cc->repeat = 0;
477-
cc->next = NULL;
477+
cc->next = *c;
478478

479479
*c = cc;
480480

@@ -693,8 +693,10 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
693693
if (r < 0)
694694
goto fail;
695695

696-
} else if (strcaseeq(p, "annually") || strcaseeq(p, "yearly")
697-
|| strcaseeq(p, "anually") /* backwards compatibility */ ) {
696+
} else if (strcaseeq(p, "annually") ||
697+
strcaseeq(p, "yearly") ||
698+
strcaseeq(p, "anually") /* backwards compatibility */ ) {
699+
698700
r = const_chain(1, &c->month);
699701
if (r < 0)
700702
goto fail;
@@ -725,6 +727,57 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
725727
if (r < 0)
726728
goto fail;
727729

730+
} else if (strcaseeq(p, "quarterly")) {
731+
732+
r = const_chain(1, &c->month);
733+
if (r < 0)
734+
goto fail;
735+
r = const_chain(4, &c->month);
736+
if (r < 0)
737+
goto fail;
738+
r = const_chain(7, &c->month);
739+
if (r < 0)
740+
goto fail;
741+
r = const_chain(10, &c->month);
742+
if (r < 0)
743+
goto fail;
744+
r = const_chain(1, &c->day);
745+
if (r < 0)
746+
goto fail;
747+
r = const_chain(0, &c->hour);
748+
if (r < 0)
749+
goto fail;
750+
r = const_chain(0, &c->minute);
751+
if (r < 0)
752+
goto fail;
753+
r = const_chain(0, &c->second);
754+
if (r < 0)
755+
goto fail;
756+
757+
} else if (strcaseeq(p, "biannually") ||
758+
strcaseeq(p, "bi-annually") ||
759+
strcaseeq(p, "semiannually") ||
760+
strcaseeq(p, "semi-annually")) {
761+
762+
r = const_chain(1, &c->month);
763+
if (r < 0)
764+
goto fail;
765+
r = const_chain(7, &c->month);
766+
if (r < 0)
767+
goto fail;
768+
r = const_chain(1, &c->day);
769+
if (r < 0)
770+
goto fail;
771+
r = const_chain(0, &c->hour);
772+
if (r < 0)
773+
goto fail;
774+
r = const_chain(0, &c->minute);
775+
if (r < 0)
776+
goto fail;
777+
r = const_chain(0, &c->second);
778+
if (r < 0)
779+
goto fail;
780+
728781
} else {
729782
r = parse_weekdays(&p, c);
730783
if (r < 0)

src/test/test-calendarspec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ int main(int argc, char* argv[]) {
7777
test_one("daily", "*-*-* 00:00:00");
7878
test_one("monthly", "*-*-01 00:00:00");
7979
test_one("weekly", "Mon *-*-* 00:00:00");
80+
test_one("minutely", "*-*-* *:*:00");
81+
test_one("quarterly", "*-01,04,07,10-01 00:00:00");
82+
test_one("semi-annually", "*-01,07-01 00:00:00");
83+
test_one("annually", "*-01-01 00:00:00");
8084
test_one("*:2/3", "*-*-* *:02/3:00");
8185

8286
assert_se(calendar_spec_from_string("test", &c) < 0);

0 commit comments

Comments
 (0)