summaryrefslogtreecommitdiff
path: root/src/timezone.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
commit6232d13f5321b87ddf12a1aa36b4545da45f173d (patch)
tree23f3316470a14136debd9d02f9e920ca2b06f4cc /src/timezone.cc
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in memroy.
Diffstat (limited to 'src/timezone.cc')
-rw-r--r--src/timezone.cc38
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));
+}