aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2020-11-15 10:25:46 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2020-12-19 09:19:59 -0500
commit1efe24105e1a516d4b16fa44eca821d914a9c387 (patch)
tree73015c2ff1d3a32d5294452bfa51d4cf5dbc0e42
parent3599766ceed52ded64987661756b4ec3cf7ed1aa (diff)
downloadcalcurse-1efe24105e1a516d4b16fa44eca821d914a9c387.tar.gz
calcurse-1efe24105e1a516d4b16fa44eca821d914a9c387.zip
Improve performance of recur_prev_occurrence()
And fix item start day for prev command Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/calcurse.c6
-rw-r--r--src/calcurse.h1
-rw-r--r--src/recur.c25
3 files changed, 19 insertions, 13 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index 7bd3d67..cd143d6 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -623,8 +623,12 @@ static inline void key_generic_cmd(void)
warnbox(error_msg);
goto cleanup;
}
- day = date2sec(*ui_calendar_get_slctd_day(), 0, 0);
item = ui_day_get_sel();
+ /*
+ * The selected day need not be the (item) start day
+ * for multi-day occurrences.
+ */
+ day = DAY(item->start);
if (item->type == RECUR_EVNT) {
rev = item->item.rev;
more = recur_next_occurrence(rev->day, -1, rev->rpt, &rev->exc,
diff --git a/src/calcurse.h b/src/calcurse.h
index 0c9b603..bd351d6 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -142,6 +142,7 @@
*/
#define DAYINSEC (DAYINMIN * MININSEC)
#define NEXTDAY(date) date_sec_change((date), 0, 1)
+#define PREVDAY(date) date_sec_change((date), 0, -1)
#define DAYLEN(date) (NEXTDAY(date) - (date))
#define ENDOFDAY(date) (NEXTDAY(date) - 1)
#define HOURINSEC (HOURINMIN * MININSEC)
diff --git a/src/recur.c b/src/recur.c
index a6c02a8..72cb40f 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -1852,19 +1852,20 @@ int recur_nth_occurrence(time_t s, long d, struct rpt *r, llist_t *e, int n,
int recur_prev_occurrence(time_t s, long d, struct rpt *r, llist_t *e,
time_t day, time_t *prev)
{
- time_t prev_day, next;
+ int ret = 0;
if (day <= DAY(s))
- return 0;
- next = *prev = s;
- while (DAY(next) < day) {
- /* Set new previous and next. */
- *prev = next;
- prev_day = DAY(*prev);
- recur_next_occurrence(s, d, r, e, prev_day, &next);
- /* Multi-day appointment */
- if (next == *prev)
- next = NEXTDAY(*prev);
+ return ret;
+
+ while (DAY(s) < day) {
+ day = PREVDAY(day);
+ if (recur_item_find_occurrence(s, d, r, e, day, prev)) {
+ /* Multi-day appointment. */
+ if (d != -1 && *prev < day && day < *prev + d)
+ continue;
+ ret = 1;
+ break;
+ }
}
- return 1;
+ return ret;
}