From 4910d9d7bbd1551646aaffc351e20c6fd15587b4 Mon Sep 17 00:00:00 2001 From: bjoernf Date: Fri, 8 Sep 2023 20:01:42 +0200 Subject: [PATCH] started with getting the DTEND and updated docs --- docs/ics_format.txt | 8 +++++++- src/insert_event.c | 16 ++++++++++------ src/insert_event.h | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/ics_format.txt b/docs/ics_format.txt index 66a926e..ac7cf1b 100644 --- a/docs/ics_format.txt +++ b/docs/ics_format.txt @@ -19,6 +19,12 @@ DTSTART;TZID=/freeassociation.sourceforge.net/Continent/City: DTEND;TZID=/freeassociation.sourceforge.net/Continent/City: 20230909T093000 -This includes the continent and city of the used time zone. +appointments can also span over multiple days: +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230913T230000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230914T040000 + +Appointments include the continent and city of the used time zone. "DESCRIPTION:" is an optional field. diff --git a/src/insert_event.c b/src/insert_event.c index f7d2965..4e5b455 100644 --- a/src/insert_event.c +++ b/src/insert_event.c @@ -18,11 +18,10 @@ void insert_event(char *file_name) { char dtstamp[] = "YYYYmmddTHHMMSSZ"; char *time_zone = get_tz(); char *dtstart_buffer = malloc(128); + char *dtend_buffer = malloc(128); remove_until_delim(time_zone, '/', 4); - printf ("tz is: %s\n", time_zone); - printf("Insert a new event\n"); printf("Is this an all day event? [y/n] "); @@ -51,10 +50,13 @@ void insert_event(char *file_name) { get_date(dtstamp); - get_dtstart(dtstart_buffer, all_day_event); + get_dtstart_dtend(dtstart_buffer, all_day_event, "start"); marshall_date_time(dtstart_buffer); form_dtstart_string(dtstart_buffer, time_zone); + get_dtstart_dtend(dtend_buffer, all_day_event, "end"); + printf ("dtend_buffer: %s\n", dtend_buffer); + seek_cal_end(myfd); write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n")); write(myfd, "UID:", strlen("UID:")); @@ -70,6 +72,7 @@ void insert_event(char *file_name) { close(myfd); free(time_zone); free(dtstart_buffer); + free(dtend_buffer); exit(0); } @@ -115,9 +118,10 @@ int binary_user_choice() { } } -void get_dtstart(char input_buffer[], int all_day_event) { +// char *start_or_end should contain "start" or "end" +void get_dtstart_dtend(char input_buffer[], int all_day_event, char *start_or_end) { if (all_day_event) { - printf("Enter the start date in YYYY-mm-dd format!\n"); + printf("Enter the %s date in YYYY-mm-dd format!\n", start_or_end); if (fgets(input_buffer, 128, stdin) == NULL) { perror ("fgets"); exit(1); @@ -127,7 +131,7 @@ void get_dtstart(char input_buffer[], int all_day_event) { exit(1); } } else { - printf("Enter the start date in YYYY-mm-dd HH:MM:SS format!\n"); + printf("Enter the %s date in YYYY-mm-dd HH:MM:SS format!\n", start_or_end); if (fgets(input_buffer, 128, stdin) == NULL) { perror ("fgets"); exit(1); diff --git a/src/insert_event.h b/src/insert_event.h index 316ae60..569a9b5 100644 --- a/src/insert_event.h +++ b/src/insert_event.h @@ -3,5 +3,5 @@ void insert_event(char *file_name); void seek_cal_end(int fd); int binary_user_choice(); -void get_dtstart(char input_buffer[], int all_day_event); +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[]);