Support durations in recurrence ending dates

When spending the end date of recurring items, allow date duration
specifiers such as "+5d" or "+3w2d".

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lukas Fleischer
2016-02-25 21:31:16 +01:00
parent c34f9aba29
commit f5d8b5e021
4 changed files with 125 additions and 34 deletions

View File

@@ -254,6 +254,7 @@ static void update_rept(struct rpt **rpt, const long start)
time_t t;
struct date new_date;
int newmonth, newday, newyear;
unsigned days;
asprintf(&outstr, _("Enter the new ending date: [%s] or '0'"),
DATEFMT_DESC(conf.input_datefmt));
@@ -270,21 +271,38 @@ static void update_rept(struct rpt **rpt, const long start)
newuntil = 0;
break;
}
if (!parse_date
(timstr, conf.input_datefmt, &newyear, &newmonth,
&newday, ui_calendar_get_slctd_day())) {
asprintf(&outstr, msg_fmts,
DATEFMT_DESC(conf.input_datefmt));
status_mesg(msg_wrong_date, outstr);
mem_free(outstr);
wgetch(win[KEY].p);
continue;
if (*timstr == '+') {
if (!parse_date_duration(timstr + 1, &days)) {
asprintf(&outstr, msg_fmts,
DATEFMT_DESC(conf.input_datefmt));
status_mesg(msg_wrong_date, outstr);
mem_free(outstr);
wgetch(win[KEY].p);
continue;
}
t = start;
localtime_r(&t, &lt);
date_change(&lt, 0, days);
new_date.dd = lt.tm_mday;
new_date.mm = lt.tm_mon + 1;
new_date.yyyy = lt.tm_year + 1900;
} else {
if (!parse_date(timstr, conf.input_datefmt, &newyear,
&newmonth, &newday,
ui_calendar_get_slctd_day())) {
asprintf(&outstr, msg_fmts,
DATEFMT_DESC(conf.input_datefmt));
status_mesg(msg_wrong_date, outstr);
mem_free(outstr);
wgetch(win[KEY].p);
continue;
}
t = start;
localtime_r(&t, &lt);
new_date.dd = newday;
new_date.mm = newmonth;
new_date.yyyy = newyear;
}
t = start;
localtime_r(&t, &lt);
new_date.dd = newday;
new_date.mm = newmonth;
new_date.yyyy = newyear;
newuntil = date2sec(new_date, lt.tm_hour, lt.tm_min);
if (newuntil >= start)
break;