Skip to content

Commit

Permalink
detect current zone on OpenWRT systems
Browse files Browse the repository at this point in the history
  • Loading branch information
paresy authored and HowardHinnant committed Sep 28, 2024
1 parent d2ddc5e commit dc9d161
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/tz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down

0 comments on commit dc9d161

Please sign in to comment.