From 2916e77056f586329ecfed657a9ca07579be69bd Mon Sep 17 00:00:00 2001 From: bjoernf Date: Fri, 8 Sep 2023 20:16:14 +0200 Subject: [PATCH] implemented DTEND --- src/insert_event.c | 28 +++++++++++++++++++++------- src/insert_event.h | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/insert_event.c b/src/insert_event.c index 4e5b455..0cbb19a 100644 --- a/src/insert_event.c +++ b/src/insert_event.c @@ -27,12 +27,6 @@ void insert_event(char *file_name) { printf("Is this an all day event? [y/n] "); all_day_event = binary_user_choice(); - if (all_day_event) { - printf("this will be an all day event\n"); - } else { - printf("this will not be an all day event\n"); - } - printf("SUMMARY: "); fgets (input_buffer, (sizeof(summary_buf)-strlen(summary_buf)), stdin); @@ -55,7 +49,8 @@ void insert_event(char *file_name) { form_dtstart_string(dtstart_buffer, time_zone); get_dtstart_dtend(dtend_buffer, all_day_event, "end"); - printf ("dtend_buffer: %s\n", dtend_buffer); + marshall_date_time(dtend_buffer); + form_dtend_string(dtend_buffer, time_zone); seek_cal_end(myfd); write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n")); @@ -66,6 +61,7 @@ void insert_event(char *file_name) { write(myfd, dtstamp, strlen(dtstamp)); write(myfd, "\r\n", strlen("\r\n")); write(myfd, dtstart_buffer, strlen(dtstart_buffer)); + write(myfd, dtend_buffer, strlen(dtend_buffer)); write(myfd, summary_buf, strlen(summary_buf)); write(myfd, "END:VCALENDAR\r\n", strlen("END:VCALENDAR\r\n")); @@ -160,3 +156,21 @@ void form_dtstart_string(char dtstart_buffer[], char time_zone[]) { } strcat(dtstart_buffer, "\r\n"); } + +void form_dtend_string(char dtend_buffer[], char time_zone[]) { + char dtend_copy[strlen(dtend_buffer)]; + strcpy(dtend_copy, dtend_buffer); + + // not all day event + if (strlen(dtend_buffer) == 15) { + strcpy(dtend_buffer, "DTEND;TZID=/freeassociation.sourceforge.net"); + strcat(dtend_buffer, time_zone); + strcat(dtend_buffer, ":\r\n "); + strcat(dtend_buffer, dtend_copy); + } else { + // all day event + strcpy(dtend_buffer, "DTEND;VALUE=DATE:"); + strcat(dtend_buffer, dtend_copy); + } + strcat(dtend_buffer, "\r\n"); +} diff --git a/src/insert_event.h b/src/insert_event.h index 569a9b5..5d012a9 100644 --- a/src/insert_event.h +++ b/src/insert_event.h @@ -5,3 +5,4 @@ void seek_cal_end(int fd); int binary_user_choice(); void get_dtstart_dtend(char input_buffer[], int all_day_event, char *start_or_end); void form_dtstart_string(char dtstart_buffer[], char time_zone[]); +void form_dtend_string(char dtend_buffer[], char time_zone[]);