From 4c7faaa1ffd0e188dddf368ef8e3ec8369f2f48d Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 7 Mar 2019 19:47:19 +0100 Subject: [PATCH] proper kml-timestamps --- src/dc_location.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/dc_location.c b/src/dc_location.c index 4de09711..792e3b98 100644 --- a/src/dc_location.c +++ b/src/dc_location.c @@ -143,6 +143,16 @@ cleanup: } +static char* get_kml_timestamp(time_t utc) +{ + // Returns a string formatted as YYYY-MM-DDTHH:MM:SSZ. The trailing `Z` indicates UTC. + struct tm wanted_struct; + memcpy(&wanted_struct, gmtime(&utc), sizeof(struct tm)); + return dc_mprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", + (int)wanted_struct.tm_year+1900, (int)wanted_struct.tm_mon+1, (int)wanted_struct.tm_mday, + (int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec); +} + char* dc_get_location_kml(dc_context_t* context, uint32_t chat_id) { @@ -150,7 +160,7 @@ char* dc_get_location_kml(dc_context_t* context, uint32_t chat_id) double latitude = 0.0; double longitude = 0.0; double accuracy = 0.0; - time_t timestamp = 0; + char* timestamp = NULL; dc_strbuilder_t ret; dc_strbuilder_init(&ret, 1000); @@ -175,17 +185,20 @@ char* dc_get_location_kml(dc_context_t* context, uint32_t chat_id) latitude = sqlite3_column_double(stmt, 0); longitude = sqlite3_column_double(stmt, 1); accuracy = sqlite3_column_double(stmt, 2); - timestamp = sqlite3_column_int64 (stmt, 3); + timestamp = get_kml_timestamp(sqlite3_column_int64 (stmt, 3)); dc_strbuilder_catf(&ret, "" - "%i" // TODO: timestamp must be formatted as 2005-08-21T09:01:00Z + "%s" "%f,%f,0" "\n", - (int)timestamp, + timestamp, accuracy, latitude, longitude); + + free(timestamp); + timestamp = NULL; } dc_strbuilder_cat(&ret,