Sha256: 4025fb745e080062f40fe06766dfa9a82b3028277791900b54d9be9a9c7b0aca

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

require "date"

module GoogleMapsService::Apis
  # Performs requests to the Google Maps TimeZone API."""
  module TimeZone
    # Get time zone for a location on the earth, as well as that location's
    # time offset from UTC.
    #
    # @example Current time zone
    #   timezone = client.timezone([39.603481, -119.682251])
    #
    # @example Time zone at certain time
    #   timezone = client.timezone([39.603481, -119.682251], timestamp: Time.at(1608))
    #
    # @param [Hash, Array] location The latitude/longitude value representing the location to
    #     look up.
    # @param [Integer, DateTime] timestamp Timestamp specifies the desired time as seconds since
    #     midnight, January 1, 1970 UTC. The 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. Optional. Defaults to
    #     `Time.now`.
    # @param [String] language The language in which to return results.
    #
    # @return [Hash] Time zone object.
    def timezone(location, timestamp: Time.now, language: nil)
      location = GoogleMapsService::Convert.latlng(location)
      timestamp = GoogleMapsService::Convert.time(timestamp)

      params = {
        location: location,
        timestamp: timestamp
      }

      params[:language] = language if language

      get("/maps/api/timezone/json", params)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
google_maps_service_ruby-0.7.0 lib/google_maps_service/apis/time_zone.rb
google_maps_service_ruby-0.6.3 lib/google_maps_service/apis/time_zone.rb
google_maps_service_ruby-0.6.2 lib/google_maps_service/apis/time_zone.rb
google_maps_service_ruby-0.6.1 lib/google_maps_service/apis/time_zone.rb
google_maps_service_ruby-0.6.0 lib/google_maps_service/apis/time_zone.rb