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);