aboutsummaryrefslogtreecommitdiffstats
path: root/src/recur.c
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2019-02-05 21:56:13 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2019-02-28 08:03:53 +0100
commit528368932ceb05fec10638062ca56d6772f21040 (patch)
tree3124e3805f923ef3461c67cf3cab576f4b378634 /src/recur.c
parenta47a562322d52275b0bae7181a5077cf95b24ffb (diff)
downloadcalcurse-528368932ceb05fec10638062ca56d6772f21040.tar.gz
calcurse-528368932ceb05fec10638062ca56d6772f21040.zip
View or edit exception days of a recurrent item
The exception days are presented for viewing/editing as a string of space-separated dates (in the user-preferred input format). After editing the string is checked for valid dates, but there is no check that a date is meaningful (an occurrence day of the item between start day and until day). Although possible, it is best to add exception days in the usual way by deletion of occurrences. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/recur.c')
-rw-r--r--src/recur.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/recur.c b/src/recur.c
index 2a0a9f7..4e8bd09 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -84,6 +84,57 @@ static void exc_dup(llist_t * in, llist_t * exc)
}
}
+/* Return a string containing the exception days. */
+char *recur_exc2str(llist_t *exc)
+{
+ llist_item_t *i;
+ struct excp *p;
+ struct string s;
+ struct tm tm;
+
+ string_init(&s);
+ LLIST_FOREACH(exc, i) {
+ p = LLIST_GET_DATA(i);
+ localtime_r(&p->st, &tm);
+ string_catftime(&s, DATEFMT(conf.input_datefmt), &tm);
+ string_catf(&s, "%c", ' ');
+ }
+ return string_buf(&s);
+}
+
+/*
+ * Update the list of exceptions from a string of days. Any positive number of
+ * spaces are allowed before, between and after the days.
+ */
+void recur_update_exc(llist_t *exc, char *days)
+{
+ char *d;
+ time_t t = get_today();
+ llist_t nexc;
+ LLIST_INIT(&nexc);
+
+ while (1) {
+ while (*days == ' ')
+ days++;
+ if ((d = strchr(days, ' ')))
+ *d = '\0';
+ else if (!strlen(days))
+ break;
+ if (parse_datetime(days, &t, 0))
+ recur_add_exc(&nexc, t);
+ else
+ goto cleanup;
+ if (d)
+ days = d + 1;
+ else
+ break;
+ }
+ free_exc_list(exc);
+ exc_dup(exc, &nexc);
+cleanup:
+ free_exc_list(&nexc);
+}
+
struct recur_event *recur_event_dup(struct recur_event *in)
{
EXIT_IF(!in, _("null pointer"));