module Eztz

Ruby wrapper for the Google Time Zone API. @example Sample usage

# Set your api key
Eztz.api_key = 'YOUR_API_KEY'
# location as a string
Eztz.timezone(location: "-33.86,151.20")
# location as an array
Eztz.timezone(location: [-33.86,151.20])

Constants

VERSION

Attributes

api_key[RW]

@!attribute api_key

@return [String] Your application's API key.
  Api keys can be obtained at
  https://developers.google.com/maps/documentation/timezone/get-api-key

Public Class Methods

client() click to toggle source

The Eztz client @return [Eztz::Client]

# File lib/eztz.rb, line 34
def client
  @client ||= Eztz::Client.new
end
configure() { |self| ... } click to toggle source

@example Configure api key with a configuration block

Eztz.configure do |config|
  config.api_key = 'XYZ'
end
# File lib/eztz.rb, line 27
def configure
  yield self
  true
end
timezone(location:, timestamp: Time.now.utc.to_i, language: 'en') click to toggle source

Gets timezone information for a location on earth, as well as that location's time offset from UTC.

@param location [String, Array] a comma-separated lat,lng tuple

(eg. "-33.86,151.20"), representing the location to look up. Can also be
an array (eg. [-33.86, 151.20]).

@param timestamp [Integer] specifies the desired time as seconds

since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses
the timestamp to determine whether or not Daylight Savings should be
applied. Times before 1970 can be expressed as negative values.
Defaults to the current time.

@param language [String] The language in which to return results

Defaults to 'en'. A list of supported languages can be found at
https://developers.google.com/maps/faq#languagesupport

@raise [ArgumentError] if location is not provided @raise [ApiError] if the API returns an error response. @return [Eztz::TimeZoneResponse] the resulting timezone data. @example Get the timezone for a location

Eztz.timezone(location: "-33.86,151.20")
=> #<Eztz::TimeZoneResponse:0x007fe71c906298 @timestamp=1488580176,
  @dst_offset=3600, @error_message=nil, @raw_offset=36000,
  @status="OK", @id="Australia/Sydney",
  @name="Australian Eastern Daylight Time">
# File lib/eztz.rb, line 61
def timezone(location:, timestamp: Time.now.utc.to_i, language: 'en')
  client.timezone(location: location,
                  timestamp: timestamp,
                  language: language)
end