diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 7448eb51d32bd5e7c3752ece401b96babffea316
parent f206c1cd15cc53395fa37da8a96428b1ee610ffe
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Fri, 31 Mar 2023 00:21:21 +0200

fix: DST drawing of calendar and movements

Fixes bugs while drawing days before/after the DST change and in the
movements between these boundaries.

Diffstat:
Msrc/diary.c | 24++++++++++++++++++------
Msrc/utils.c | 1+
2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/diary.c b/src/diary.c @@ -15,8 +15,15 @@ struct tm cal_end; void setup_cal_timeframe() { raw_time = time(NULL); localtime_r(&raw_time, &today); - curs_date = today; + today.tm_sec = 0; + today.tm_min = 0; + today.tm_hour = 0; + // ignore dst, irrelevant for the daily schedule + // and only overthrows calendar drawing on change days + today.tm_isdst = 0; + mktime(&today); + curs_date = today; cal_start = today; cal_start.tm_year -= CONFIG.range; cal_start.tm_mon = 0; @@ -35,6 +42,10 @@ void setup_cal_timeframe() { cal_end.tm_year += CONFIG.range; cal_end.tm_mon = 11; cal_end.tm_mday = 31; + cal_end.tm_sec = 59; + cal_end.tm_min = 59; + cal_end.tm_hour = 23; + cal_end.tm_isdst = 0; mktime(&cal_end); } @@ -73,7 +84,6 @@ void draw_calendar(WINDOW* number_pad, WINDOW* month_pad, const char* diary_dir, } i.tm_mday++; - mktime(&i); } } @@ -272,6 +282,7 @@ struct tm find_closest_entry(const struct tm current, struct tm it = current; it.tm_mday += step; + it.tm_isdst = 0; time_t it_time = mktime(&it); for( ; it_time >= start_time && it_time <= end_time; it_time = mktime(&it)) { @@ -279,6 +290,7 @@ struct tm find_closest_entry(const struct tm current, return it; } it.tm_mday += step; + it.tm_isdst = 0; } return current; @@ -593,7 +605,7 @@ int main(int argc, char** argv) { int prev_height = LINES - 1; size_t diary_dir_size = strlen(CONFIG.dir); - bool mv_valid = go_to(cal, aside, raw_time, &pad_pos, &curs_date, &cal_start, &cal_end); + bool mv_valid = go_to(cal, aside, mktime(&today), &pad_pos, &curs_date, &cal_start, &cal_end); // mark current day atrs = winch(cal) & A_ATTRIBUTES; wchgat(cal, 2, atrs | A_UNDERLINE, 0, NULL); @@ -615,11 +627,13 @@ int main(int argc, char** argv) { // new_date represents the desired date the user wants to go_to(), // which may not be a feasible date at all new_date = curs_date; + new_date.tm_isdst = 0; char ecmd[150]; char* pecmd = ecmd; char pth[100]; char* ppth = pth; char dstr[16]; + mktime(&new_date); edit_cmd(CONFIG.dir, diary_dir_size, &new_date, &pecmd, sizeof ecmd); switch(ch) { @@ -745,8 +759,7 @@ int main(int argc, char** argv) { // today shortcut case 't': - new_date = today; - mv_valid = go_to(cal, aside, raw_time, &pad_pos, &curs_date, &cal_start, &cal_end); + mv_valid = go_to(cal, aside, mktime(&today), &pad_pos, &curs_date, &cal_start, &cal_end); break; // delete entry case 'd': @@ -851,7 +864,6 @@ int main(int argc, char** argv) { // reset confirmation char from previous sync attempts conf_ch = 0; for( ; new_datetime <= end_of_month; new_datetime = mktime(&new_date)) { - // this udpates curs_date (todo: document this better) go_to(cal, aside, mktime(&new_date), &pad_pos, &curs_date, &cal_start, &cal_end); update_date(header, &curs_date); if (conf_ch == -1) { diff --git a/src/utils.c b/src/utils.c @@ -346,6 +346,7 @@ bool go_to(WINDOW* calendar, WINDOW* aside, time_t date, int* cur_pad_pos, struc int diff_wdays = diff_days % 7; localtime_r(&date, curs_date); + mktime(curs_date); int cy, cx; getyx(calendar, cy, cx);