detect current zone on OpenWRT systems

This commit is contained in:
Michael Maroszek 2023-05-21 00:24:32 +02:00 committed by Howard Hinnant
parent d2ddc5ea1e
commit dc9d161607

View File

@ -4170,6 +4170,25 @@ tzdb::current_zone() const
} }
// Fall through to try other means. // 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"); throw std::runtime_error("Could not get current timezone");
} }