scal

Simple Calendar
git clone git://git.wimdupont.com/scal.git
Log | Files | Refs | LICENSE

commit 73f7f9f3fb1223faf72b7568e917c61c3ce3697b
parent 61e8168e16c1a2e66a01d3ffd4743473788b5714
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sun, 16 Mar 2025 22:49:49 +0100

fix daily recurring cross year

Diffstat:
Mscal.c | 42++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/scal.c b/scal.c @@ -46,7 +46,7 @@ static int get_note_view_col(Recurring recurring); static int get_days(const struct tm *tm); static int days_between(struct tm *tsa, struct tm *tsb); static int is_relevant(Note *note, struct tm *a); -static int same_day(struct tm *a, struct tm *b, Recurring recurring); +static int same_day(struct tm *a, struct tm *b); static int compare_note(const void *a, const void *b); static void move_page_up(void); static void move_page_down(void); @@ -192,7 +192,7 @@ print_month(const int monthadd, int *y) for (size_t i = 0; i < wcount; ++i) { otm.tm_mday=i+1; - today = same_day(&otm, &curtm, 0); + today = same_day(&otm, &curtm); notecol = get_relevant_recur(&otm); if (today) @@ -772,15 +772,30 @@ is_relevant(Note *note, struct tm *a) timegm(&note->end); timegm(a); - return (note->end.tm_year > a->tm_year + if ((note->end.tm_year > a->tm_year || (note->end.tm_yday >= a->tm_yday && note->end.tm_year == a->tm_year)) && (note->time.tm_year < a->tm_year - || (note->time.tm_yday <= a->tm_yday && note->time.tm_year == a->tm_year)) - && same_day(&(note->time), a, note->recurring); + || (note->time.tm_yday <= a->tm_yday && note->time.tm_year == a->tm_year))) { + switch (note->recurring) { + case DAILY: + return note->time.tm_yday <= a->tm_yday || note->end.tm_year > a->tm_year; + case WEEKLY: + return note->time.tm_wday == a->tm_wday; + case MONTHLY: + return note->time.tm_mday == a->tm_mday; + case YEARLY: + return note->time.tm_mday == a->tm_mday && note->time.tm_mon == a->tm_mon; + case NO: + return note->time.tm_yday == a->tm_yday && note->time.tm_year == a->tm_year; + default: + return 0; + } + } + return 0; } int -same_day(struct tm *a, struct tm *b, Recurring recurring) +same_day(struct tm *a, struct tm *b) { if (a == NULL || b == NULL) return 0; @@ -788,20 +803,7 @@ same_day(struct tm *a, struct tm *b, Recurring recurring) timegm(a); timegm(b); - switch (recurring) { - case DAILY: - return a->tm_yday <= b->tm_yday; - case WEEKLY: - return a->tm_wday == b->tm_wday; - case MONTHLY: - return a->tm_mday == b->tm_mday; - case YEARLY: - return a->tm_mday == b->tm_mday && a->tm_mon == b->tm_mon; - case NO: - return a->tm_yday == b->tm_yday && a->tm_year == b->tm_year; - default: - return 0; - } + return a->tm_yday == b->tm_yday && a->tm_year == b->tm_year; } int