fixed pretty_print_date_time
This commit is contained in:
parent
33d9fed0cf
commit
578bf0b0f5
@ -22,6 +22,10 @@ void get_date(char buffer[]) {
|
|||||||
|
|
||||||
// 20230823T194138 -> 2023-08-23 19:41:38
|
// 20230823T194138 -> 2023-08-23 19:41:38
|
||||||
void pretty_print_date_time(char date_time[]) {
|
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 *date = strtok(date_time, "T");
|
||||||
char *time = strtok(NULL, "T");
|
char *time = strtok(NULL, "T");
|
||||||
if (date == NULL) {
|
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[2], time[3]);
|
||||||
printf ("%c%c", time[4], time[5]);
|
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[]) {
|
void marshall_date_time(char date_time[]) {
|
||||||
|
@ -8,6 +8,9 @@ test_parse_ics_file:
|
|||||||
test_print_upcoming:
|
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
|
$(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
|
.PHONY:clean
|
||||||
clean:
|
clean:
|
||||||
-rm -vf *.out
|
-rm -vf *.out
|
||||||
|
14
unit-tests/test_pretty_print_date_time.c
Normal file
14
unit-tests/test_pretty_print_date_time.c
Normal 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));
|
||||||
|
}
|
@ -6,7 +6,9 @@ int main() {
|
|||||||
// initialize empty list
|
// initialize empty list
|
||||||
struct event *head = NULL;
|
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);
|
parse_ics_file("/home/bf/.local/share/evolution/calendar/system/calendar.ics", &head);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user