diff options
Diffstat (limited to 'src/timezone.cc')
| -rw-r--r-- | src/timezone.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/timezone.cc b/src/timezone.cc new file mode 100644 index 0000000..ca0f501 --- /dev/null +++ b/src/timezone.cc @@ -0,0 +1,38 @@ +#include "common.hh" + +#include "geo_json.hh" +#include "timezone.hh" +#include "tz_info.hh" + +namespace { + +class TimezoneImpl : public Timezone { +public: + TimezoneImpl(std::shared_ptr<Logger> logger, + std::filesystem::path geojsondb, + std::filesystem::path tzinfo_dir) + : geojson_(GeoJson::create(logger, std::move(geojsondb))), + tzinfo_(TzInfo::create(logger, std::move(tzinfo_dir))) { + } + + std::optional<time_t> get_local_time(double lat, double lng, + time_t utc_time) const override { + auto tzid = geojson_->get_data(lat, lng, "tzid"); + if (tzid.has_value()) + return tzinfo_->get_local_time(tzid.value(), utc_time); + return std::nullopt; + } + +private: + std::unique_ptr<GeoJson> geojson_; + std::unique_ptr<TzInfo> tzinfo_; +}; + +} // namespace + +std::unique_ptr<Timezone> Timezone::create(std::shared_ptr<Logger> logger, + std::filesystem::path geojsondb, + std::filesystem::path tzinfo_dir) { + return std::make_unique<TimezoneImpl>(std::move(logger), std::move(geojsondb), + std::move(tzinfo_dir)); +} |
