added pretty_print_date_time function

This commit is contained in:
bjt-user 2023-08-23 20:03:26 +02:00
parent 8f1e0e7b1d
commit 0294dbf3e9
4 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,5 @@
#include "date_time_handling.h"
#include <stdio.h>
#include <time.h>
#include <string.h>
@ -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]);
}
}

View File

@ -2,3 +2,4 @@
#include <string.h>
void get_date(char buffer[]);
void pretty_print_date_time(char date_time[]);

View File

@ -1,4 +1,5 @@
#include "list_handling.h"
#include "date_time_handling.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ -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;
}

View File

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