calendarspec: be more graceful with two kinds of calendar expressions
authorLennart Poettering <lennart@poettering.net>
Thu, 30 Apr 2020 11:24:31 +0000 (13:24 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 30 May 2020 18:15:37 +0000 (20:15 +0200)
commite06b9407928cd6ab8a5058765fa3e29bb8fb12d7
tree526e8ae783c1bc54ecbbb168ad053439b48785b8
parentf3dd0b476d9d36638310962f54ed211bc4638bba
calendarspec: be more graceful with two kinds of calendar expressions

This changes the calendarspec parser to allow expressions such as
"00:05..05", i.e. a range where start and end is the same. It also
allows expressions such as "00:1-2/3", i.e. where the repetition value
does not fit even once in the specified range. With this patch both
cases will now be optimized away, i.e. the range is removed and a fixed
value is used, which is functionally equivalent.

See #15030 for an issue where the inability to parse such expressions
caused confusion.

I think it's probably better to accept these gracefully and optimizing
them away instead of refusing them with a plain EINVAL. With a tool such
as "systemd-analyze" calendar it should be easy to figure out the
normalized form with the redundant bits optimized away.

(cherry picked from commit c9c9f6f450f678a0d5e5b929ba238d4a5254bded)
src/shared/calendarspec.c
src/test/test-calendarspec.c