TimeLogic API | A World Time API

Official Ruby SDK for TimeLogic API, providing world time, timezone, calendar, and signed response operations.

Installation

Build a gem

To build the Ruby code into a gem:

gem build timelogic-api.gemspec

Then either install the gem locally:

gem install ./timelogic-api-1.0.0.gem

(for development, run gem install --dev ./timelogic-api-1.0.0.gem to install the development dependencies)

or publish the gem to a gem hosting service, e.g. RubyGems.

Finally add this to the Gemfile:

gem 'timelogic-api', '~> 1.0.0'

Install from Git

If the Ruby gem is hosted at a git repository: https://github.com/TimeLogic-API-LLC/timelogic-api-sdks.git, then add the following in the Gemfile:

gem 'timelogic-api', :git => 'https://github.com/TimeLogic-API-LLC/timelogic-api-sdks.git'

Include the Ruby code directly

Include the Ruby code directly using -I as follows:

ruby -Ilib script.rb

Getting Started

Please follow the installation procedure and then run the following code:

# Load the gem
require 'timelogic-api'

# Setup authorization
TimeLogic::Api.configure do |config|
  # Configure API key authorization: directApiKeyHeader
  config.api_key['X-API-Key'] = 'YOUR API KEY'
  # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
  # config.api_key_prefix['X-API-Key'] = 'Bearer'

  # Configure Bearer authorization (TimeLogic API key): directBearerAuth
  config.access_token = 'YOUR_BEARER_TOKEN'
  # Configure a proc to get access tokens in lieu of the static access_token configuration
  config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' } 

  # Configure API key authorization: directApiKeyQuery
  config.api_key['api_key'] = 'YOUR API KEY'
  # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
  # config.api_key_prefix['api_key'] = 'Bearer'

  # Configure API key authorization: rapidApiKey
  config.api_key['X-RapidAPI-Key'] = 'YOUR API KEY'
  # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
  # config.api_key_prefix['X-RapidAPI-Key'] = 'Bearer'

  # Configure API key authorization: rapidApiHost
  config.api_key['X-RapidAPI-Host'] = 'YOUR API KEY'
  # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
  # config.api_key_prefix['X-RapidAPI-Host'] = 'Bearer'
end

api_instance = TimeLogic::Api::TimeApi.new
opts = {
  unix: 1711300000, # Integer | 
  unix_ms: 1711300000000, # Integer | 
  iso: '2024-03-24T15:00:00', # String | ISO-8601 timestamp. To supply a local wall-clock time without an explicit offset, pair it with one of `source_tz=Area/City`, `source_ip=...`, `source_lat=...&source_lon=...`, or `source_offset=±HH:MM`.
  source_tz: 'America/New_York', # String | Used only with `iso=...` when the ISO value has no explicit offset.
  source_ip: '8.8.8.8', # String | Used only with `iso=...` when the ISO value has no explicit offset. Resolves that local wall-clock time through the timezone mapped from this IP address.
  source_lat: 40.7128, # Float | Used only with `iso=...` when the ISO value has no explicit offset. Provide together with `source_lon` to resolve that local wall-clock time through the timezone mapped from these coordinates.
  source_lon: -74.006, # Float | Used only with `iso=...` when the ISO value has no explicit offset. Provide together with `source_lat`.
  source_offset: '-05:00', # String | Used only with `iso=...` when the ISO value has no explicit offset. Interprets that local wall-clock time at this fixed UTC offset.
  seconds: 30, # Integer | 
  minutes: 15, # Integer | 
  hours: 2, # Integer | 
  days: 7, # Integer | 
  tz: 'America/New_York', # String | IANA timezone name. On bulk-capable routes, a comma-separated list enables bulk mode.
  ip: '8.8.8.8', # String | IP address. On bulk-capable routes, a comma-separated list enables bulk mode.
  lat: 40.7128, # Float | Latitude. Must be provided together with `lon`.
  lon: -74.006, # Float | Longitude. Must be provided together with `lat`.
  offset: '-04:00', # String | Fixed UTC offset in `+HH:MM` or `-HH:MM` format. On bulk-capable routes, a comma-separated list enables bulk mode.
  auto_tz: true, # Boolean | Set to `true` to resolve using the caller IP from Cloudflare headers.
  utc: true, # Boolean | Set to `true` to force UTC on routes that support it.
  format: '%Y-%m-%d %H:%M:%S', # String | Custom date/time format template using supported `strftime`-style directives such as `%Y-%m-%d %H:%M:%S`. Reference: [strftime](https://strftime.net/).
  sign: true # Boolean | Set to exactly `true` to ask the gateway to sign the final JSON response. Every authenticated JSON response, including errors, then includes signing headers. Not supported on `/v1/time/clock`.
}

begin
  #Add modifiers to a timestamp
  result = api_instance.add_time(opts)
  p result
rescue TimeLogic::Api::ApiError => e
  puts "Exception when calling TimeApi->add_time: #{e}"
end

Documentation for API Endpoints

All URIs are relative to https://api.timelogicapi.com

Class Method HTTP request Description
TimeLogic::Api::TimeApi add_time GET /v1/time/add Add modifiers to a timestamp
TimeLogic::Api::TimeApi convert_time GET /v1/time/convert Convert a timestamp into a target timezone or offset
TimeLogic::Api::TimeApi diff_time GET /v1/time/diff Difference between two instants
TimeLogic::Api::TimeApi get_calendar GET /v1/time/calendar Calendar projection for a target instant
TimeLogic::Api::TimeApi get_clock GET /v1/time/clock Render a live HTML clock
TimeLogic::Api::TimeApi get_current_time GET /v1/time/current Get the current time for a target
TimeLogic::Api::TimeApi get_dst GET /v1/time/dst Daylight-saving status for a target
TimeLogic::Api::TimeApi get_elapsed GET /v1/time/elapsed Time elapsed since or remaining until a reference instant
TimeLogic::Api::TimeApi get_timezone GET /v1/timezone Resolve timezone information for a target
TimeLogic::Api::UtilityApi get_public_signing_key GET /.well-known/time-api-public-key Public signing key set

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

directBearerAuth

  • Type: Bearer authentication (TimeLogic API key)

directApiKeyHeader

  • Type: API key
  • API key parameter name: X-API-Key
  • Location: HTTP header

directApiKeyQuery

  • Type: API key
  • API key parameter name: api_key
  • Location: URL query string

rapidApiKey

  • Type: API key
  • API key parameter name: X-RapidAPI-Key
  • Location: HTTP header

rapidApiHost

  • Type: API key
  • API key parameter name: X-RapidAPI-Host
  • Location: HTTP header