From 66454922e1857bf92fe2603b4d881d7f16fec5fe Mon Sep 17 00:00:00 2001 From: bjoernf Date: Sun, 10 Sep 2023 11:36:46 +0200 Subject: [PATCH] fixed printing of excluded DTEND day for all day events --- README.md | 2 +- src/date_time_handling.c | 16 +++++++++++++++- src/date_time_handling.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9319563..41cc6b4 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,6 @@ sudo make uninstall #### TODO +- fix bug when LOCATION field is present - cap the number of upcoming events being printed (and introduce --all option) -- don't show the DTEND day of an all day event, but DTEND - 1 - tests diff --git a/src/date_time_handling.c b/src/date_time_handling.c index f917d9f..bb35d3d 100644 --- a/src/date_time_handling.c +++ b/src/date_time_handling.c @@ -70,7 +70,10 @@ void print_end_date(char end_date[], char start_date[]) { return; } else { printf (" - "); - pretty_print_date_time(end_date); + end_uts -= 86400; + char *end_date_minus_one = transform_unix_ts_to_date(end_uts); + pretty_print_date_time(end_date_minus_one); + free(end_date_minus_one); return; } } else { @@ -110,6 +113,17 @@ time_t transform_date_to_unix_ts(char date_str[]) { return unix_stamp; } +// unix timestamp -> YYYYmmdd +// make sure to free the returned buffer +char *transform_unix_ts_to_date(time_t unix_ts) { + char *date_buffer = malloc(9); + struct tm *my_tm; + my_tm = localtime(&unix_ts); + strftime(date_buffer, 9, "%Y%m%d", my_tm); + + return date_buffer; +} + char *get_tz() { char *timezone_path = malloc(256); ssize_t bytes_read = readlink("/etc/localtime", timezone_path, 255); diff --git a/src/date_time_handling.h b/src/date_time_handling.h index 2f713d9..509ccaf 100644 --- a/src/date_time_handling.h +++ b/src/date_time_handling.h @@ -7,3 +7,4 @@ void pretty_print_date_time(char date_time[]); void marshall_date_time(char date_time[]); void print_end_date(char end_date[], char start_date[]); time_t transform_date_to_unix_ts(char date_str[]); +char *transform_unix_ts_to_date(time_t unix_ts);