scal

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

commit 9539a0a3cec60567b842c939a90e55a78bb00428
parent e05c5842cace7a63233102069300708c72eac2d8
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sun, 10 Nov 2024 19:01:02 +0100

fix weekly

Diffstat:
Mscal.c | 24++++++++++++------------
Mscal.h | 6+++---
2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/scal.c b/scal.c @@ -193,10 +193,12 @@ start() case 10: print_view(); break; + case KEY_RIGHT: case KEY_VRIGHT: case KEY_VRIGHT_ABS: move_right(); break; + case KEY_LEFT: case KEY_VLEFT: case KEY_VLEFT_ABS: move_left(); @@ -387,10 +389,7 @@ prompt_answer(char *buf, size_t size, const char *question, const char *mask, ch static void add_note(struct tm *tm) { size_t len; - char answer[DESCLEN+20]; - char buf[DESCLEN]; - char rec[2], time[6], date[11]; - char prefill[11]; + char answer[DESCLEN+20], buf[DESCLEN], rec[2], time[6], date[11], prefill[11]; if (tm != NULL) snprintf(prefill, 11, "%04d-%02d-%02d\0", @@ -563,8 +562,7 @@ get_note(char *line_buf, ssize_t line_size) static void print_view() { - int y = -1, x = 0; - int color; + int y = -1, x = 0, color; get_curnotes(); @@ -624,7 +622,7 @@ get_note_view_col(Recurring recurring) } static int -has_note(const struct tm *tm) +has_note(struct tm *tm) { for (int i = 0; i < note_count; i++) { if (same_day(&(notes[i]->time), tm, notes[i]->recurring)) @@ -634,10 +632,9 @@ has_note(const struct tm *tm) } static int -get_days(struct tm *tm) +get_days(const struct tm *tm) { - struct tm start = *tm; - struct tm end = *tm; + struct tm start = *tm, end = *tm; start.tm_mday=1; end.tm_mon = start.tm_mon+1; @@ -656,12 +653,15 @@ days_between(struct tm *tsa, struct tm *tsb) } static int -same_day(const struct tm *a, const struct tm *b, Recurring recurring) +same_day(struct tm *a, struct tm *b, Recurring recurring) { if (a == NULL || b == NULL) return 0; - return ((recurring == WEEKLY && ((a->tm_mday - b->tm_mday) %7) == 0) || a->tm_mday == b->tm_mday ) + mktime(a); + mktime(b); + + return ((recurring == WEEKLY && a->tm_wday == b->tm_wday) || a->tm_mday == b->tm_mday ) && (recurring >= MONTHLY || a->tm_mon == b->tm_mon) && (recurring >= YEARLY || a->tm_year == b->tm_year); } diff --git a/scal.h b/scal.h @@ -68,10 +68,10 @@ static void add_note(struct tm *tm); static void rm_note(struct tm *tm); static int get_curnotes(); static int get_note_view_col(Recurring recurring); -static int has_note(const struct tm *tm); -static int get_days(struct tm *tm); +static int has_note(struct tm *tm); +static int get_days(const struct tm *tm); static int days_between(struct tm *tsa, struct tm *tsb); -static int same_day(const struct tm *a, const struct tm *b, Recurring recurring); +static int same_day(struct tm *a, struct tm *b, Recurring recurring); static int compare_note(const void *a, const void *b); static void move_top(); static void move_bot();