From 3599766ceed52ded64987661756b4ec3cf7ed1aa Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Sun, 15 Nov 2020 10:23:10 +0100 Subject: Introduce macro DAY DAY(t) is midnight (the day) of time_t t. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/calcurse.c | 2 +- src/calcurse.h | 1 + src/day.c | 4 ++-- src/ical.c | 4 ++-- src/io.c | 8 ++++---- src/recur.c | 22 ++++++++++------------ src/ui-day.c | 25 ++++++++++--------------- src/utils.c | 5 ++--- 8 files changed, 32 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/calcurse.c b/src/calcurse.c index 3083f86..7bd3d67 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -668,7 +668,7 @@ static inline void key_generic_cmd(void) * The selected day need not be the (item) start day * for multi-day occurrences. */ - day = update_time_in_date(item->start, 0, 0); + day = DAY(item->start); if (item->type == RECUR_EVNT) { rev = item->item.rev; more = recur_prev_occurrence(rev->day, -1, rev->rpt, diff --git a/src/calcurse.h b/src/calcurse.h index 4dc5968..0c9b603 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -145,6 +145,7 @@ #define DAYLEN(date) (NEXTDAY(date) - (date)) #define ENDOFDAY(date) (NEXTDAY(date) - 1) #define HOURINSEC (HOURINMIN * MININSEC) +#define DAY(date) (update_time_in_date(date, 0, 0)) /* Calendar window. */ #define CALHEIGHT 8 diff --git a/src/day.c b/src/day.c index 5bf84c4..6a18dc1 100644 --- a/src/day.c +++ b/src/day.c @@ -100,7 +100,7 @@ int day_sel_index(void) /* If still not found, stay on the same day. */ VECTOR_FOREACH(&day_items, i) { p = VECTOR_NTH(&day_items, i); - if (p->order == update_time_in_date(sel_data.order, 0, 0)) + if (p->order == DAY(sel_data.order)) return i; } return -1; @@ -832,7 +832,7 @@ int day_paste_item(struct day_item *p, time_t date) /* wanted: until = shift + old_until */ if (p->item.rapt->rpt->until && overflow_add( - date - update_time_in_date(p->item.rapt->start, 0, 0), + date - DAY(p->item.rapt->start), p->item.rapt->rpt->until, &until) ) diff --git a/src/ical.c b/src/ical.c index ad96f11..7c3768e 100644 --- a/src/ical.c +++ b/src/ical.c @@ -584,7 +584,7 @@ ical_store_apoint(char *mesg, char *note, time_t start, long dur, * calcurse until day must be changed to the day before. */ if (rpt->until) { - day = update_time_in_date(rpt->until, 0, 0); + day = DAY(rpt->until); if (recur_item_find_occurrence(start, dur, rpt, NULL, day, NULL) && get_item_time(rpt->until) < get_item_time(start)) @@ -1550,7 +1550,7 @@ ical_read_event(FILE * fdi, FILE * log, unsigned *noevents, char *msg; dur = vevent_type == EVENT ? -1 : vevent.dur; - day = update_time_in_date(vevent.start, 0, 0); + day = DAY(vevent.start); msg = _("rrule does not match start day (%s)."); if (vevent.count) { diff --git a/src/io.c b/src/io.c index ff61dae..71960f5 100644 --- a/src/io.c +++ b/src/io.c @@ -237,25 +237,25 @@ void io_dump_apts(const char *fmt_apt, const char *fmt_rapt, LLIST_FOREACH(&recur_elist, i) { struct recur_event *rev = LLIST_GET_DATA(i); - time_t day = update_time_in_date(rev->day, 0, 0); + time_t day = DAY(rev->day); print_recur_event(fmt_rev, day, rev); } LLIST_TS_FOREACH(&recur_alist_p, i) { struct recur_apoint *rapt = LLIST_GET_DATA(i); - time_t day = update_time_in_date(rapt->start, 0, 0); + time_t day = DAY(rapt->start); print_recur_apoint(fmt_rapt, day, rapt->start, rapt); } LLIST_TS_FOREACH(&alist_p, i) { struct apoint *apt = LLIST_TS_GET_DATA(i); - time_t day = update_time_in_date(apt->start, 0, 0); + time_t day = DAY(apt->start); print_apoint(fmt_apt, day, apt); } LLIST_FOREACH(&eventlist, i) { struct event *ev = LLIST_TS_GET_DATA(i); - time_t day = update_time_in_date(ev->day, 0, 0); + time_t day = DAY(ev->day); print_event(fmt_ev, day, ev); } } diff --git a/src/recur.c b/src/recur.c index 3a16d1e..a6c02a8 100644 --- a/src/recur.c +++ b/src/recur.c @@ -517,8 +517,7 @@ char *recur_apoint_scan(FILE *f, struct tm start, struct tm end, /* Does it occur on the start day? */ if (!recur_item_find_occurrence(tstart, tend - tstart, rpt, NULL, - update_time_in_date(tstart, 0, 0), - NULL)) { + DAY(tstart), NULL)) { char *fmt = _("recurrence error: not on start day (%s)"); return day_ins(&fmt, tstart); } @@ -590,8 +589,7 @@ char *recur_event_scan(FILE * f, struct tm start, int id, /* Does it occur on the start day? */ if (!recur_item_find_occurrence(tstart, -1, rpt, NULL, - update_time_in_date(tstart, 0, 0), - NULL)) { + DAY(tstart), NULL)) { char *fmt = _("recurrence error: not on start day (%s)"); return day_ins(&fmt, tstart); } @@ -1209,7 +1207,7 @@ static int expand_monthly(time_t start, long dur, struct rpt *rpt, llist_t *exc, -WEEKINDAYS ); r.until = date_sec_change( - update_time_in_date(nstart, 0, 0), + DAY(nstart), 0, r.freq * WEEKINDAYS ); @@ -1243,7 +1241,7 @@ static int expand_monthly(time_t start, long dur, struct rpt *rpt, llist_t *exc, -WEEKINDAYS ); r.until = date_sec_change( - update_time_in_date(nstart, 0, 0), + DAY(nstart), 0, r.freq * WEEKINDAYS ); @@ -1349,7 +1347,7 @@ static int expand_yearly(time_t start, long dur, struct rpt *rpt, llist_t *exc, -WEEKINDAYS ); r.until = date_sec_change( - update_time_in_date(nstart, 0, 0), + DAY(nstart), 0, r.freq * WEEKINDAYS ); @@ -1394,7 +1392,7 @@ static int expand_yearly(time_t start, long dur, struct rpt *rpt, llist_t *exc, -WEEKINDAYS ); r.until = date_sec_change( - update_time_in_date(nstart, 0, 0), + DAY(nstart), 0, r.freq * WEEKINDAYS ); @@ -1840,7 +1838,7 @@ int recur_nth_occurrence(time_t s, long d, struct rpt *r, llist_t *e, int n, return 0; for (n--, *nth = s; n > 0; n--) { - day = update_time_in_date(*nth, 0, 0); + day = DAY(*nth); if (!recur_next_occurrence(s, d, r, e, day, nth)) break; } @@ -1856,13 +1854,13 @@ int recur_prev_occurrence(time_t s, long d, struct rpt *r, llist_t *e, { time_t prev_day, next; - if (day <= update_time_in_date(s, 0, 0)) + if (day <= DAY(s)) return 0; next = *prev = s; - while (update_time_in_date(next, 0, 0) < day) { + while (DAY(next) < day) { /* Set new previous and next. */ *prev = next; - prev_day = update_time_in_date(*prev, 0, 0); + prev_day = DAY(*prev); recur_next_occurrence(s, d, r, e, prev_day, &next); /* Multi-day appointment */ if (next == *prev) diff --git a/src/ui-day.c b/src/ui-day.c index 613e242..ae810ed 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -79,7 +79,7 @@ void ui_day_find_sel(void) */ time_t ui_day_sel_date(void) { - return update_time_in_date(ui_day_get_sel()->order, 0, 0); + return DAY(ui_day_get_sel()->order); } /* @@ -184,10 +184,9 @@ static void update_start_time(time_t *start, long *dur, struct rpt *rpt, int mov newtime = day_edit_time(*start, *dur, move); if (!newtime) break; - if (rpt && !recur_item_find_occurrence( - newtime, *dur, rpt, NULL, - update_time_in_date(newtime, 0, 0), - NULL)) { + if (rpt && !recur_item_find_occurrence(newtime, *dur, rpt, NULL, + DAY(newtime), + NULL)) { msg = day_ins(&msg_match, newtime); status_mesg(msg, msg_enter); mem_free(msg); @@ -786,10 +785,7 @@ static int update_rept(time_t start, long dur, struct rpt **rpt, llist_t *exc, continue; } /* Until is midnight of the day. */ - nrpt.until = date_sec_change( - update_time_in_date(start, 0, 0), - 0, days - ); + nrpt.until = date_sec_change(DAY(start), 0, days); } else if (*timstr == '#') { char *eos; count = strtol(timstr + 1, &eos, 10); @@ -802,7 +798,7 @@ static int update_rept(time_t start, long dur, struct rpt **rpt, llist_t *exc, keys_wgetch(win[KEY].p); continue; } - nrpt.until = update_time_in_date(until, 0, 0); + nrpt.until = DAY(until); break; } else { int year, month, day; @@ -816,7 +812,7 @@ static int update_rept(time_t start, long dur, struct rpt **rpt, llist_t *exc, nrpt.until = date2sec(d, 0, 0); } /* Conmpare days (midnights) - until-day may equal start day. */ - if (nrpt.until >= update_time_in_date(start, 0, 0)) + if (nrpt.until >= DAY(start)) break; mem_free(timstr); @@ -884,7 +880,7 @@ static int update_rept(time_t start, long dur, struct rpt **rpt, llist_t *exc, keys_wgetch(win[KEY].p); goto cleanup; } - nrpt.until = update_time_in_date(until, 0, 0); + nrpt.until = DAY(until); } /* * Check whether the start occurrence matches the recurrence rule, in @@ -895,8 +891,7 @@ static int update_rept(time_t start, long dur, struct rpt **rpt, llist_t *exc, char *msg_match = _("Repetition must begin on start day (%s); " "any change discarded."); - if (!recur_item_find_occurrence(start, dur, &nrpt, NULL, - update_time_in_date(start, 0, 0), + if (!recur_item_find_occurrence(start, dur, &nrpt, NULL, DAY(start), NULL)) { mem_free(outstr); outstr = day_ins(&msg_match, start); @@ -1525,7 +1520,7 @@ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) { struct day_item *item = day_get_item(n); /* The item order always indicates the date. */ - time_t date = update_time_in_date(item->order, 0, 0); + time_t date = DAY(item->order); int width = lb_apt.sw.w - 2, is_slctd; hilt = hilt && (wins_slctd() == APP); diff --git a/src/utils.c b/src/utils.c index 2d2f615..114a985 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1643,7 +1643,7 @@ static void print_date(time_t date, time_t day, const char *extformat) if (!strcmp(extformat, "epoch")) { printf("%ld", (long)date); } else { - time_t day_start = update_time_in_date(day, 0, 0); + time_t day_start = DAY(day); time_t day_end = date_sec_change(day_start, 0, 1); struct tm lt; @@ -2079,8 +2079,7 @@ char *day_ins(char **template, time_t t) { char *day, *msg; - day = date_sec2date_str(update_time_in_date(t, 0 , 0), - DATEFMT(conf.input_datefmt)); + day = date_sec2date_str(DAY(t), DATEFMT(conf.input_datefmt)); asprintf(&msg, *template, day); mem_free(day); return msg; -- cgit v1.2.3-54-g00ecf