From f5d8b5e021a62bf3e36e18aa9aebee331fece8dd Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 25 Feb 2016 21:31:16 +0100 Subject: 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 --- src/ui-day.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'src/ui-day.c') diff --git a/src/ui-day.c b/src/ui-day.c index 63c5da8..fdb3c09 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -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, <); + date_change(<, 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, <); + new_date.dd = newday; + new_date.mm = newmonth; + new_date.yyyy = newyear; } - t = start; - localtime_r(&t, <); - 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; -- cgit v1.2.3-54-g00ecf