commit f5301c3970ac054c9cefd8c009e11a4652e38ab6
parent 10ec60f0fbf64df94a31b52ed703a82febe26afa
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Mon, 17 Jan 2022 01:27:29 +0100
feat(caldav): use utc time
Diffstat:
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/caldav.c b/src/caldav.c
@@ -150,8 +150,9 @@ void write_tokenfile() {
}
fclose(tokenfile);
- chmod(tokenfile_path, S_IRUSR|S_IWUSR);
- perror("chmod");
+ if (chmod(tokenfile_path, S_IRUSR|S_IWUSR) == -1) {
+ perror("chmod");
+ }
char* tokfile = read_tokenfile();
free(tokfile);
@@ -625,7 +626,7 @@ int caldav_sync(struct tm* date,
if (user_principal == NULL) {
free(user_principal);
- fprintf(stderr, "Unable to fetch principal, refreshing API token.\n");
+ fprintf(stderr, "Info - Unable to fetch principal, refreshing API token.\n");
// The principal could not be fetched,
// get new acess token with refresh token
get_access_token(NULL, NULL, true);
@@ -713,18 +714,18 @@ int caldav_sync(struct tm* date,
if (stat(path, &attr) != 0) {
perror("Stat failed");
// local file does probably not exist
- localfile_time = localtime(&epoch_zero);
+ localfile_time = gmtime(&epoch_zero);
} else {
// remember utc time of file on disk
- localfile_time = localtime(&attr.st_mtime);
+ localfile_time = gmtime(&attr.st_mtime);
}
// set to negative value, so mktime uses timezone information and system databases
// to attempt to determine whether DST is in effect at the specified time
- localfile_time->tm_isdst = -1;
+ // localfile_time->tm_isdst = -1;
time_t localfile_date = mktime(localfile_time);
- struct tm remote_datetime;
+ struct tm remote_datetime = {0};
time_t remote_date;
long search_pos = 0;
@@ -737,14 +738,16 @@ int caldav_sync(struct tm* date,
remote_date = epoch_zero;
} else {
strptime(remote_last_mod, "%Y%m%dT%H%M%SZ", &remote_datetime);
- remote_datetime.tm_isdst = -1;
+ // remote_datetime.tm_isdst = -1;
remote_date = mktime(&remote_datetime);
free(remote_last_mod);
free(remote_uid);
}
+ fprintf(stderr, "Info - remote last mod: %s\n", ctime(&remote_date));
+ fprintf(stderr, "Info - local last mod: %s\n", ctime(&localfile_date));
double timediff = difftime(localfile_date, remote_date);
- fprintf(stderr, "Info - time diff between local and remote mod time:%e\n", timediff);
+ fprintf(stderr, "Info - Time diff between local and remote mod time:%e\n", timediff);
char* rmt_desc;