Compare commits
3 Commits
9bba31490b
...
c20f1ca1f0
Author | SHA1 | Date | |
---|---|---|---|
c20f1ca1f0 | |||
578bf0b0f5 | |||
33d9fed0cf |
@ -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[]) {
|
||||
|
@ -46,10 +46,10 @@ void free_list(struct event *head)
|
||||
}
|
||||
}
|
||||
|
||||
void print_upcoming(struct event *head, char current_start_date[], int show_all_events) {
|
||||
void print_upcoming(struct event *head, char current_date[], int show_all_events) {
|
||||
int i = 0;
|
||||
while (head != NULL) {
|
||||
if (strcmp(head->start_date, current_start_date) >= 0) {
|
||||
if (strcmp(head->start_date, current_date) >= 0) {
|
||||
pretty_print_date_time(head->start_date);
|
||||
print_end_date(head->end_date, head->start_date);
|
||||
printf("\nSUMMARY: %s\n", head->summary);
|
||||
|
@ -5,6 +5,12 @@ test_parse_ics_file:
|
||||
$(CC) $(CFLAGS) test_parse_ics_file.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_parse_ics_file.out
|
||||
./test_parse_ics_file.out
|
||||
|
||||
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
|
||||
|
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));
|
||||
}
|
16
unit-tests/test_print_upcoming.c
Normal file
16
unit-tests/test_print_upcoming.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include "../src/list_handling.h"
|
||||
#include "../src/parse_ics.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// initialize empty list
|
||||
struct event *head = NULL;
|
||||
|
||||
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);
|
||||
|
||||
print_upcoming(head, current_date, 0);
|
||||
}
|
Reference in New Issue
Block a user