From 22db336f6187a7f8f0a67043a3662510fe418bad Mon Sep 17 00:00:00 2001
From: Sam Oliver <sam@samoliver.com>
Date: Mon, 24 Jul 2017 13:40:24 +0100
Subject: [PATCH] Add `time_zone` to `Opencagedata` result

---
 lib/geocoder/results/opencagedata.rb   | 9 +++++++++
 test/unit/lookups/opencagedata_test.rb | 5 ++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/geocoder/results/opencagedata.rb b/lib/geocoder/results/opencagedata.rb
index 94407dbc..2c8fbb7c 100644
--- a/lib/geocoder/results/opencagedata.rb
+++ b/lib/geocoder/results/opencagedata.rb
@@ -75,6 +75,15 @@ module Geocoder::Result
       [south, west, north, east]
     end
 
+    def time_zone
+      # The OpenCage API documentation states that `annotations` is available
+      # "when possible" https://geocoder.opencagedata.com/api#annotations
+      @data
+        .fetch('annotations', {})
+        .fetch('timezone', {})
+        .fetch('name', nil)
+    end
+
     def self.response_attributes
       %w[boundingbox license 
         formatted stadium]
diff --git a/test/unit/lookups/opencagedata_test.rb b/test/unit/lookups/opencagedata_test.rb
index 7ed0eb32..b8ad20de 100644
--- a/test/unit/lookups/opencagedata_test.rb
+++ b/test/unit/lookups/opencagedata_test.rb
@@ -60,7 +60,10 @@ class OpencagedataTest < GeocoderTestCase
     assert_match(/\bq=45.423733%2C-75.676333\b/, query.url)
   end
 
-
+  def test_opencagedata_time_zone
+    result = Geocoder.search("Madison Square Garden, New York, NY").first
+    assert_equal "America/New_York", result.time_zone
+  end
 
   def test_raises_exception_when_invalid_request
     Geocoder.configure(always_raise: [Geocoder::InvalidRequest])
-- 
GitLab