Sha256: 49dca0e437fcf9336021d8c8a125fdd8a042511f5815535fcbe2f14b100bce8c

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require 'date'

module GoogleMapsService

  # 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.
    #
    # @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]
    def timezone(location: nil,
                 timestamp: nil, language: nil)
      location = GoogleMapsService::Convert.latlng(location)
      timestamp = GoogleMapsService::Convert.time(timestamp || Time.now)

      params = {
        location: location,
        timestamp: timestamp
      }

      params[:language] = language if language

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
google_maps_service-0.3.0 lib/google_maps_service/time_zone.rb
google_maps_service-0.2.0 lib/google_maps_service/time_zone.rb
google_maps_service-0.1.0 lib/google_maps_service/time_zone.rb