Add local time support for windows

This commit is contained in:
Michael Krasnyk
2017-06-02 17:01:59 +02:00
parent 0e39320a77
commit 50d9c4b34a
11 changed files with 278 additions and 49 deletions
+9
View File
@@ -16,6 +16,8 @@
#include <string>
#include <unordered_map>
#include <time.h>
// Function loads time zone shape polygons, computes a zone local time for utc_time,
// creates a lookup R-tree and returns a lambda function that maps a point
// to the corresponding local time
@@ -86,9 +88,15 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
if (it == local_time_memo.end())
{
struct tm timeinfo;
#if defined(_WIN32)
_putenv_s("TZ", tzname);
_tzset();
localtime_s(&timeinfo, &utc_time);
#else
setenv("TZ", tzname, 1);
tzset();
localtime_r(&utc_time, &timeinfo);
#endif
it = local_time_memo.insert({tzname, timeinfo}).first;
}
@@ -158,6 +166,7 @@ boost::optional<struct tm> Timezoner::operator()(const point_t &point) const
if (boost::geometry::within(point, local_times[index].first))
return local_times[index].second;
}
return boost::none;
}
}
}