From 96c1977037365a52afab6834b660db6081ed67ff Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Fri, 11 Mar 2022 16:19:44 +0100 Subject: [PATCH] Fixing timeoffset --- lib/obp60task/OBP60Formater.cpp | 33 +++++++++++++++++++++++++++------ lib/obp60task/config.json | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/obp60task/OBP60Formater.cpp b/lib/obp60task/OBP60Formater.cpp index b22ee19..080d7e0 100644 --- a/lib/obp60task/OBP60Formater.cpp +++ b/lib/obp60task/OBP60Formater.cpp @@ -9,6 +9,8 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ FormatedData result; + static int dayoffset = 0; + // Load configuration values int timeZone = commondata.config->getInt(commondata.config->timeZone); // [UTC -12...+12] String lengthFormat = commondata.config->getString(commondata.config->lengthFormat); // [m|ft] @@ -31,7 +33,7 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ time_t tv = 0; if (value->getFormat() == "formatDate"){ tmElements_t parts; - time_t tv=tNMEA0183Msg::daysToTime_t(value->value); + time_t tv=tNMEA0183Msg::daysToTime_t(value->value + dayoffset); tNMEA0183Msg::breakTime(tv,parts); if(usesimudata == false) { if(String(dateFormat) == "DE"){ @@ -59,11 +61,12 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ } //######################################################## else if(value->getFormat() == "formatTime"){ - double timeInSeconds; - double inthr; - double intmin; - double intsec; - double val; + double timeInSeconds = 0; + double utcTime = 0; + double inthr = 0; + double intmin = 0; + double intsec = 0; + double val = 0; if(timeZone > 0){ timeInSeconds = value->value + timeZone * 3600; @@ -74,6 +77,24 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ timeInSeconds = int(timeInSeconds) % 86400; // Reduce to one day (86400s) } + // Changing day depends on time offset + utcTime = value->value; + if(timeZone + (utcTime/3600) > 24 && timeZone > 0){ + dayoffset = 1; + } + else{ + dayoffset = 0; + } + if(timeZone == 0){ + dayoffset = 0; + } + if(timeZone + (utcTime/3600) > 24 && timeZone < 0){ + dayoffset = 0; + } + else{ + dayoffset = -1; + } + if(usesimudata == false) { val=modf(timeInSeconds/3600.0,&inthr); diff --git a/lib/obp60task/config.json b/lib/obp60task/config.json index c5c24fb..aa43391 100644 --- a/lib/obp60task/config.json +++ b/lib/obp60task/config.json @@ -16,7 +16,7 @@ "type": "number", "default": "0", "check": "checkMinMax", - "min": -12, + "min": -18, "max": 14, "description": "Time zone [UTC -12...+14]", "category": "OBP60 Settings",