mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-10 11:25:41 +00:00
Some more fixes to usage of gmtime (#1150)
* Some more fixes to usage of gmtime * Second version for drv_ntp_events.c - changing to time_t (hence do casting in calculations) * Fix for unset NTP time if no NTP drivers present. Rely on "fake" definitions of NTP_GetCurrentTime() and NTP_GetCurrentTimeWithoutOffset() to make sure code using time is not called, if it is not set. * If time is not set, give 1970-01-01T00:00:00 as startupUTC
This commit is contained in:
@ -653,14 +653,15 @@ static int http_tasmota_json_status_generic(void* request, jsonCb_t printer) {
|
||||
JSON_PrintKeyValue_String(request, printer, "RestartReason", "HardwareWatchdog", true);
|
||||
JSON_PrintKeyValue_Int(request, printer, "Uptime", g_secondsElapsed, true);
|
||||
struct tm* ltm;
|
||||
int ntpTime = NTP_GetCurrentTime() - g_secondsElapsed;
|
||||
ltm = gmtime((time_t*)&ntpTime);
|
||||
|
||||
time_t ntpTime = 0; // if no NTP_time set, we will not change this value, but just stick to 0 and hence "fake" start of epoch 1970-01-01T00:00:00
|
||||
if (NTP_GetCurrentTimeWithoutOffset() > g_secondsElapsed) { // would be negative else, leading to unwanted results when converted to (unsigned) time_t
|
||||
ntpTime = (time_t)NTP_GetCurrentTimeWithoutOffset() - (time_t)g_secondsElapsed;
|
||||
}
|
||||
ltm = gmtime(&ntpTime);
|
||||
if (ltm != 0) {
|
||||
printer(request, "\"StartupUTC\":\"%04d-%02d-%02dT%02d:%02d:%02d\",", ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
JSON_PrintKeyValue_Int(request, printer, "Sleep", 50, true);
|
||||
JSON_PrintKeyValue_Int(request, printer, "CfgHolder", 4617, true);
|
||||
|
||||
Reference in New Issue
Block a user