summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorDouglas Christman <DouglasChristman@gmail.com>2016-11-24 15:41:04 -0500
committerDouglas Christman <DouglasChristman@gmail.com>2016-11-24 18:40:14 -0500
commit9904dc00e70c44762f63c05bce703f2a2a0e46bb (patch)
treed0a23e0515d4e4d6f09bce6a435c06d6081c898a /src/basic
parent36ff0c979258844ca8a200f49d434997299416e6 (diff)
calendarspec: make specifications with ranges reversible
"*-*-01..03" is now formatted as "*-*-01..03" instead of "*-*-01,02,03"
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/calendarspec.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c
index 4ef22dfffb..0caa1d4696 100644
--- a/src/basic/calendarspec.c
+++ b/src/basic/calendarspec.c
@@ -255,6 +255,8 @@ static void format_weekdays(FILE *f, const CalendarSpec *c) {
}
static void format_chain(FILE *f, int space, const CalendarComponent *c, bool usec) {
+ const CalendarComponent *n, *p;
+
assert(f);
if (!c) {
@@ -279,7 +281,23 @@ static void format_chain(FILE *f, int space, const CalendarComponent *c, bool us
fprintf(f, "/%i.%06i", (int) (c->repeat / USEC_PER_SEC), (int) (c->repeat % USEC_PER_SEC));
}
- if (c->next) {
+ p = c;
+ for (;;) {
+ n = p->next;
+
+ if (!n || n->repeat || p->repeat)
+ break;
+
+ if (n->value - p->value != (usec ? (int) USEC_PER_SEC : 1))
+ break;
+
+ p = n;
+ }
+
+ if (p->value - c->value >= 2 * (usec ? (int) USEC_PER_SEC : 1)) {
+ fputs("..", f);
+ format_chain(f, space, p, usec);
+ } else if (c->next) {
fputc(',', f);
format_chain(f, space, c->next, usec);
}