Check the TZ env variable before defaulting to /etc/localtime.

Note that only location-based timezones (e.g. 'America/Los_Angeles' are supported.
This commit is contained in:
John Ralls 2016-09-23 18:26:43 +02:00
parent 4ad901f4cf
commit bffb5d1283

View File

@ -351,14 +351,17 @@ namespace IANAParser
find_tz_file(const std::string& name)
{
std::ifstream ifs;
if (name.empty())
auto tzname = name;
if (tzname.empty())
tzname = std::string(std::getenv("TZ"));
std::cout << "Testing tzname " << tzname << "\n";
if (tzname.empty())
{
ifs.open("/etc/localtime",
std::ios::in|std::ios::binary|std::ios::ate);
}
else
{
std::string tzname = name;
//POSIX specifies that that identifier should begin with ':', but we
//should be liberal. If it's there, it's not part of the filename.
if (tzname[0] == ':')