From 0294dbf3e9728dedd8e5641e6fb7a6cda496b1cb Mon Sep 17 00:00:00 2001 From: bjt-user Date: Wed, 23 Aug 2023 20:03:26 +0200 Subject: [PATCH] added pretty_print_date_time function --- src/date_time_handling.c | 14 ++++++++++++++ src/date_time_handling.h | 1 + src/list_handling.c | 5 +++-- src/main.c | 5 +++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/date_time_handling.c b/src/date_time_handling.c index e2bb470..69aa8ea 100644 --- a/src/date_time_handling.c +++ b/src/date_time_handling.c @@ -1,4 +1,5 @@ #include "date_time_handling.h" +#include #include #include @@ -10,3 +11,16 @@ void get_date(char buffer[]) { strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local); } +// 20230823T194138 -> 2023-08-23 19:41:38 +void pretty_print_date_time(char date_time[]) { + char *date = strtok(date_time, "T"); + char *time = strtok(NULL, "T"); + printf ("%c%c%c%c-", date[0], date[1], date[2], date[3]); + printf ("%c%c-", date[4], date[5]); + printf ("%c%c", date[6], date[7]); + if (time != NULL) { + printf (" %c%c:", time[0], time[1]); + printf ("%c%c:", time[2], time[3]); + printf ("%c%c", time[4], time[5]); + } +} diff --git a/src/date_time_handling.h b/src/date_time_handling.h index 3d2b3ec..e4e815f 100644 --- a/src/date_time_handling.h +++ b/src/date_time_handling.h @@ -2,3 +2,4 @@ #include void get_date(char buffer[]); +void pretty_print_date_time(char date_time[]); diff --git a/src/list_handling.c b/src/list_handling.c index 13d216e..f55990c 100644 --- a/src/list_handling.c +++ b/src/list_handling.c @@ -1,4 +1,5 @@ #include "list_handling.h" +#include "date_time_handling.h" #include #include #include @@ -46,8 +47,8 @@ void free_list(struct event *head) void print_upcoming(struct event *head, char current_date[]) { while (head != NULL) { if (strcmp(head->date, current_date) >= 0) { - printf("%s\n", head->date); - printf("%s\n", head->summary); + pretty_print_date_time(head->date); + printf("\n%s\n", head->summary); } head = head->next; } diff --git a/src/main.c b/src/main.c index 758905f..6e21055 100644 --- a/src/main.c +++ b/src/main.c @@ -30,7 +30,9 @@ int main(int argc, char **argv) { static char current_date[] = "xxxxxxxxTxxxxxx"; get_date(current_date); - printf ("Current date and time: %s\n\n", current_date); + printf ("Current date and time: "); + pretty_print_date_time(current_date); + printf ("\n"); char date[256] = ""; char summary[256] = ""; @@ -60,7 +62,6 @@ int main(int argc, char **argv) { memset(my_line, '\0', sizeof(my_line)); } - //print_list(head); print_upcoming(head, current_date); free_list(head);