From c179467be27b4af990121ee22b6d95001cca61f0 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Thu, 21 Jan 2021 11:40:37 +0300 Subject: [PATCH] ntp: do not override existing ntpTZ --- code/espurna/ntp.cpp | 46 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/code/espurna/ntp.cpp b/code/espurna/ntp.cpp index 2fd0cd27..f0b8a413 100644 --- a/code/espurna/ntp.cpp +++ b/code/espurna/ntp.cpp @@ -231,7 +231,7 @@ void _ntpConfigure() { const auto cfg_tz = getSetting("ntpTZ", NTP_TIMEZONE); const char* active_tz = getenv("TZ"); - bool changed { cfg_tz != active_tz }; + bool changed = cfg_tz != active_tz; if (changed) { setenv("TZ", cfg_tz.c_str(), 1); tzset(); @@ -363,6 +363,7 @@ void _ntpSetTimestamp(time_t ts) { // ----------------------------------------------------------------------------- void _ntpConvertLegacyOffsets() { + bool save { true }; bool found { false }; bool europe { true }; @@ -371,7 +372,9 @@ void _ntpConvertLegacyOffsets() { settings::kv_store.foreach([&](settings::kvs_type::KeyValueResult&& kv) { const auto key = kv.key.read(); - if (key == F("ntpOffset")) { + if (key == F("ntpTZ")) { + save = false; + } else if (key == F("ntpOffset")) { offset = kv.value.read().toInt(); found = true; } else if (key == F("ntpDST")) { @@ -383,34 +386,31 @@ void _ntpConvertLegacyOffsets() { } }); - if (!found) { - return; - } + if (save && found) { + // XXX: only expect offsets in hours + String custom { europe ? F("CET") : F("CST") }; + custom.reserve(32); - // XXX: only expect offsets in hours - String custom { europe ? F("CET") : F("CST") }; - custom.reserve(32); - - if (offset > 0) { - custom += '-'; - } - custom += abs(offset) / 60; - - if (dst) { - custom += europe ? F("CEST") : F("EDT"); - if (europe) { - custom += F(",M3.5.0,M10.5.0/3"); - } else { - custom += F(",M3.2.0,M11.1.0"); + if (offset > 0) { + custom += '-'; } + custom += abs(offset) / 60; + + if (dst) { + custom += europe ? F("CEST") : F("EDT"); + if (europe) { + custom += F(",M3.5.0,M10.5.0/3"); + } else { + custom += F(",M3.2.0,M11.1.0"); + } + } + + setSetting("ntpTZ", custom); } delSetting("ntpOffset"); delSetting("ntpDST"); delSetting("ntpRegion"); - - setSetting("ntpTZ", custom); - } void ntpSetup() {