Browse Source

ntp: do not override existing ntpTZ

mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
c179467be2
1 changed files with 23 additions and 23 deletions
  1. +23
    -23
      code/espurna/ntp.cpp

+ 23
- 23
code/espurna/ntp.cpp View File

@ -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() {


Loading…
Cancel
Save