DTSTART field was implemented
This commit is contained in:
parent
af4658f472
commit
717edb9520
@ -1,4 +1,5 @@
|
||||
#include "date_time_handling.h"
|
||||
#include "string_handling.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -38,6 +39,26 @@ void pretty_print_date_time(char date_time[]) {
|
||||
}
|
||||
}
|
||||
|
||||
void marshall_date_time(char date_time[]) {
|
||||
char transformed_string[strlen(date_time)];
|
||||
int j = 0;
|
||||
remove_nl_and_cr(date_time);
|
||||
for (int i = 0; i<=strlen(date_time); i++) {
|
||||
if (date_time[i] != ':' && date_time[i] != '-') {
|
||||
if (date_time[i] == ' ') {
|
||||
transformed_string[j] = 'T';
|
||||
} else {
|
||||
transformed_string[j] = date_time[i];
|
||||
}
|
||||
|
||||
j++;
|
||||
}
|
||||
|
||||
}
|
||||
memset(date_time, '\0', strlen(date_time));
|
||||
strcpy(date_time, transformed_string);
|
||||
}
|
||||
|
||||
void print_end_date(char end_date[]) {
|
||||
// end_date is all day event
|
||||
if (strlen(end_date) == 8)
|
||||
|
@ -4,4 +4,5 @@
|
||||
void get_date(char buffer[]);
|
||||
char *get_tz();
|
||||
void pretty_print_date_time(char date_time[]);
|
||||
void marshall_date_time(char date_time[]);
|
||||
void print_end_date(char end_date[]);
|
||||
|
@ -17,6 +17,8 @@ void insert_event(char *file_name) {
|
||||
char uuid_str[37] = "";
|
||||
char dtstamp[] = "YYYYmmddTHHMMSSZ";
|
||||
char *time_zone = get_tz();
|
||||
char *dtstart_buffer = malloc(128);
|
||||
|
||||
remove_until_delim(time_zone, '/', 4);
|
||||
|
||||
printf ("tz is: %s\n", time_zone);
|
||||
@ -49,6 +51,10 @@ void insert_event(char *file_name) {
|
||||
|
||||
get_date(dtstamp);
|
||||
|
||||
get_dtstart(dtstart_buffer, all_day_event);
|
||||
marshall_date_time(dtstart_buffer);
|
||||
form_dtstart_string(dtstart_buffer, time_zone);
|
||||
|
||||
seek_cal_end(myfd);
|
||||
write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n"));
|
||||
write(myfd, "UID:", strlen("UID:"));
|
||||
@ -57,11 +63,13 @@ void insert_event(char *file_name) {
|
||||
write(myfd, "DTSTAMP:", strlen("DTSTAMP:"));
|
||||
write(myfd, dtstamp, strlen(dtstamp));
|
||||
write(myfd, "\r\n", strlen("\r\n"));
|
||||
write(myfd, dtstart_buffer, strlen(dtstart_buffer));
|
||||
write(myfd, summary_buf, strlen(summary_buf));
|
||||
write(myfd, "END:VCALENDAR\r\n", strlen("END:VCALENDAR\r\n"));
|
||||
|
||||
close(myfd);
|
||||
free(time_zone);
|
||||
free(dtstart_buffer);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@ -106,3 +114,45 @@ int binary_user_choice() {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void get_dtstart(char input_buffer[], int all_day_event) {
|
||||
if (all_day_event) {
|
||||
printf("Enter the start date in YYYY-mm-dd format!\n");
|
||||
if (fgets(input_buffer, 128, stdin) == NULL) {
|
||||
perror ("fgets");
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(input_buffer) != 11) {
|
||||
printf ("Wrong format!\n");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
printf("Enter the start date in YYYY-mm-dd HH:MM:SS format!\n");
|
||||
if (fgets(input_buffer, 128, stdin) == NULL) {
|
||||
perror ("fgets");
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(input_buffer) != 20) {
|
||||
printf ("Wrong format!\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void form_dtstart_string(char dtstart_buffer[], char time_zone[]) {
|
||||
char dtstart_copy[strlen(dtstart_buffer)];
|
||||
strcpy(dtstart_copy, dtstart_buffer);
|
||||
|
||||
// not all day event
|
||||
if (strlen(dtstart_buffer) == 15) {
|
||||
strcpy(dtstart_buffer, "DTSTART;TZID=/freeassociation.sourceforge.net");
|
||||
strcat(dtstart_buffer, time_zone);
|
||||
strcat(dtstart_buffer, ":\r\n ");
|
||||
strcat(dtstart_buffer, dtstart_copy);
|
||||
} else {
|
||||
// all day event
|
||||
strcpy(dtstart_buffer, "DTSTART;VALUE=DATE:");
|
||||
strcat(dtstart_buffer, dtstart_copy);
|
||||
}
|
||||
strcat(dtstart_buffer, "\r\n");
|
||||
}
|
||||
|
@ -3,3 +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 form_dtstart_string(char dtstart_buffer[], char time_zone[]);
|
||||
|
Loading…
Reference in New Issue
Block a user