From 0f9b81296959bc197ab194cda0837fa9ffa0d5dd Mon Sep 17 00:00:00 2001 From: Jeremy Poulter Date: Sat, 18 Mar 2023 17:07:33 +0000 Subject: [PATCH] Fixing getting the time from the EVSE The EVSE month is 1-12, `tm` is 0-11. Setting was fixed in https://github.com/jeremypoulter/OpenEVSE_Lib/commit/53c0d8487572cb3fb7b95590e7f4158e6f345bc5 but not the get. Also `getTime` uses mktime and this is localtime only so changed `setTime` to user `localtime_r` to match as there is no equivient of `mktime` for GMT/UTC. --- src/openevse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openevse.cpp b/src/openevse.cpp index 424a56b..b336921 100644 --- a/src/openevse.cpp +++ b/src/openevse.cpp @@ -152,7 +152,7 @@ void OpenEVSEClass::getTime(std::function callback) memset(&tm, 0, sizeof(tm)); tm.tm_year = 100+year; - tm.tm_mon = month; + tm.tm_mon = month - 1; tm.tm_mday = day; tm.tm_hour = hour; tm.tm_min = minute; @@ -177,7 +177,7 @@ void OpenEVSEClass::setTime(time_t time, std::function callback) // S1 yr mo day hr min sec - set clock (RTC) yr=2-digit year struct tm tm; - gmtime_r(&time, &tm); + localtime_r(&time, &tm); setTime(tm, callback); }