Class: TZ

Inherits:
Object
  • Object
show all
Defined in:
lib/us_time_zones.rb

Class Method Summary collapse

Class Method Details

.whichTZ?(point) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/us_time_zones.rb', line 32

def self.whichTZ?(point)
	pointObject = GeoRuby::SimpleFeatures::Point.from_x_y(point[0], point[1])
	url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=#{point[0].to_s},#{point[1].to_s}&key=AIzaSyBgUT0t3K3y9cKJgITa8X1O7uGYjguNZT4"
	response = HTTParty.get(url).to_json
	response = JSON.parse(response)

	if response["results"] == []
		return "Error"
	elsif response["results"][0]["formatted_address"].include?("USA")
		if Eastern.contains_point?(pointObject)
			return "US Eastern Time Zone"
		elsif Central.contains_point?(pointObject)
			return "US Central Time Zone"
		elsif Pacific.contains_point?(pointObject)
			return "US Pacific Time Zone"
		elsif Mountain.contains_point?(pointObject)
			return "US Mountain Time Zone"
		elsif Hawaii_aleutian_1.contains_point?(pointObject) || Hawaii_aleutian_2.contains_point?(pointObject)
			return "US Hawaii-Aleutian Time Zone"
		elsif Alaska.contains_point?(pointObject)
			return "US Alaska Time Zone"
		end	
	else
		return "Unable to determine time zone for coordinates outside the US"
	end
end