From dc9d161607137f00c1747477c7de7406dc97f5fa Mon Sep 17 00:00:00 2001 From: Michael Maroszek Date: Sun, 21 May 2023 00:24:32 +0200 Subject: [PATCH] detect current zone on OpenWRT systems --- src/tz.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/tz.cpp b/src/tz.cpp index aa6b7bd..dcadf40 100644 --- a/src/tz.cpp +++ b/src/tz.cpp @@ -4170,6 +4170,25 @@ tzdb::current_zone() const } // Fall through to try other means. } + // On OpenWRT we need to check /etc/config/system + // It will have a line with the following structure + // ... + // option zoneName 'Europe/Berlin' + // ... + { + std::ifstream timezone_file("/etc/config/system"); + if (timezone_file.is_open()) + { + for(std::string result; std::getline(timezone_file, result);) { + std::string findStr = "option zoneName '"; + size_t startPos = result.find(findStr); + if (startPos != std::string::npos) { + size_t endPos = result.find("'", startPos + findStr.size()); + return locate_zone(result.substr(startPos + findStr.size(), endPos - startPos - findStr.size())); + } + } + } + } throw std::runtime_error("Could not get current timezone"); }