mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-26 07:53:16 +08:00
detect current zone on OpenWRT systems
This commit is contained in:
parent
d2ddc5ea1e
commit
dc9d161607
19
src/tz.cpp
19
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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user