From 72a88b18d99710d47a0108ae781787dd2b43ef03 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 20 May 2024 20:59:03 +0200 Subject: [PATCH] Fix the date/time with timezone offset When using the dc_datetime_gmtime() function for a timestamp with a timezone offset, the timezone offset needs to be added to the timestamp prior to the call. --- src/divesoft_freedom_parser.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 9647511..55b6faf 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -709,13 +709,21 @@ divesoft_freedom_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *date return status; unsigned int timestamp = array_uint32_le (data + 8); - dc_ticks_t ticks = (dc_ticks_t) timestamp + EPOCH; + + int timezone = 0; + if (parser->version == HEADER_SIGNATURE_V2) { + timezone = ((signed short) array_uint16_le (data + 40)) * 60; + } else { + timezone = 0; + } + + dc_ticks_t ticks = (dc_ticks_t) timestamp + EPOCH + timezone; if (!dc_datetime_gmtime (datetime, ticks)) return DC_STATUS_DATAFORMAT; if (parser->version == HEADER_SIGNATURE_V2) { - datetime->timezone = ((signed short) array_uint16_le (data + 40)) * 60; + datetime->timezone = timezone; } else { datetime->timezone = DC_TIMEZONE_NONE; }