From 27a69bee93d9e64dceb4150489c10cd30e1d002d Mon Sep 17 00:00:00 2001 From: bjoernf Date: Sun, 3 Sep 2023 08:07:13 +0200 Subject: [PATCH] extended get_date func for DTSTAMP --- src/date_time_handling.c | 8 +++++++- src/insert_event.c | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/date_time_handling.c b/src/date_time_handling.c index e7e6a17..b2010dd 100644 --- a/src/date_time_handling.c +++ b/src/date_time_handling.c @@ -4,12 +4,18 @@ #include #include +// buffer needs to contain this string: "xxxxxxxxTxxxxxx" +// or "YYYYmmddTHHMMSSZ" void get_date(char buffer[]) { // add 1 because strlen does not include the null character size_t buffer_size = strlen(buffer) + 1; time_t my_unix_ts = time(NULL); struct tm* my_tm_local = localtime(&my_unix_ts); - strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local); + if (strlen(buffer) == 15) { + strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local); + } else if (strlen(buffer) == 16) { + strftime(buffer, buffer_size, "%Y%m%dT%H%M%SZ", my_tm_local); + } } // 20230823T194138 -> 2023-08-23 19:41:38 diff --git a/src/insert_event.c b/src/insert_event.c index bf62390..049d555 100644 --- a/src/insert_event.c +++ b/src/insert_event.c @@ -1,4 +1,5 @@ #include "insert_event.h" +#include "date_time_handling.h" #include #include #include @@ -13,6 +14,7 @@ void insert_event(char *file_name) { char *input_buffer = &summary_buf[8]; uuid_t uuid; char uuid_str[37] = ""; + char dtstamp[] = "YYYYmmddTHHMMSSZ"; printf("Insert a new event\n"); @@ -40,11 +42,16 @@ void insert_event(char *file_name) { // parse uuid to a string uuid_unparse(uuid, uuid_str); + get_date(dtstamp); + seek_cal_end(myfd); write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n")); write(myfd, "UID:", strlen("UID:")); write(myfd, uuid_str, strlen(uuid_str)); write(myfd, "\r\n", strlen("\r\n")); + write(myfd, "DTSTAMP:", strlen("DTSTAMP:")); + write(myfd, dtstamp, strlen(dtstamp)); + write(myfd, "\r\n", strlen("\r\n")); write(myfd, summary_buf, strlen(summary_buf)); write(myfd, "END:VCALENDAR\r\n", strlen("END:VCALENDAR\r\n")); @@ -75,7 +82,6 @@ void seek_cal_end(int fd) { } } - int binary_user_choice() { char input_buffer[64] = ""; if (fgets (input_buffer, sizeof(input_buffer), stdin) == NULL) {