fixed pretty_print_date_time

This commit is contained in:
bjt-user 2024-07-10 16:42:43 +02:00
parent 33d9fed0cf
commit 578bf0b0f5
4 changed files with 27 additions and 1 deletions

View File

@ -22,6 +22,10 @@ void get_date(char buffer[]) {
// 20230823T194138 -> 2023-08-23 19:41:38
void pretty_print_date_time(char date_time[]) {
// copy date_time because strtok will destroy it
char date_time_copy[15] = "";
strcpy(date_time_copy, date_time);
char *date = strtok(date_time, "T");
char *time = strtok(NULL, "T");
if (date == NULL) {
@ -37,6 +41,9 @@ void pretty_print_date_time(char date_time[]) {
printf ("%c%c:", time[2], time[3]);
printf ("%c%c", time[4], time[5]);
}
// put variable date_time back together
strcpy(date_time, date_time_copy);
}
void marshall_date_time(char date_time[]) {

View File

@ -8,6 +8,9 @@ test_parse_ics_file:
test_print_upcoming:
$(CC) $(CFLAGS) test_print_upcoming.c ../src/parse_ics.c ../src/string_handling.c ../src/list_handling.c ../src/date_time_handling.c ../src/read_until_string.c ../src/read_until_nl.c -o test_print_upcoming.out
test_pretty_print_date_time:
$(CC) $(CFLAGS) test_pretty_print_date_time.c ../src/string_handling.c ../src/date_time_handling.c ../src/read_until_string.c ../src/read_until_nl.c -o test_pretty_print_date_time.out
.PHONY:clean
clean:
-rm -vf *.out

View File

@ -0,0 +1,14 @@
#include "../src/date_time_handling.h"
#include <stdio.h>
int main() {
char current_date[] = "20240710T103000";
printf("current_date: %s\n", current_date);
printf("strlen(current_date): %ld\n\n", strlen(current_date));
pretty_print_date_time(current_date);
printf("\n\ncurrent_date: %s\n", current_date);
printf("strlen(current_date): %ld\n", strlen(current_date));
}

View File

@ -6,7 +6,9 @@ int main() {
// initialize empty list
struct event *head = NULL;
char *current_date = "20240710T103000";
char *current_date = "20240710T113000";
printf("DEBUG - current_date: %s\n\n", current_date);
parse_ics_file("/home/bf/.local/share/evolution/calendar/system/calendar.ics", &head);