Module: Timezone

Defined in:
lib/timezone.rb,
lib/timezone/zone.rb,
lib/timezone/error.rb,
lib/timezone/loader.rb,
lib/timezone/lookup.rb,
lib/timezone/parser.rb,
lib/timezone/version.rb,
lib/timezone/nil_zone.rb,
lib/timezone/deprecate.rb,
lib/timezone/lookup/test.rb,
lib/timezone/lookup/basic.rb,
lib/timezone/lookup/google.rb,
lib/timezone/lookup/geonames.rb,
lib/timezone/net_http_client.rb

Overview

Main entry point for all timezone related functionality.

Defined Under Namespace

Modules: Deprecate, Error, Lookup Classes: NilZone, Zone

Constant Summary collapse

VERSION =
'1.3.27'

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Timezone::Zone, Timezone::NilZone

Retrieve a timezone by name.

Parameters:

  • name (String)

    the timezone name

Returns:



23
24
25
# File 'lib/timezone.rb', line 23

def self.[](name)
  fetch(name) { ::Timezone::NilZone.new }
end

.fetch(name, default = :__block) {|name| ... } ⇒ Timezone::Zone, Object

Fetch a timezone by name.

Parameters:

  • name (String)

    the timezone name

  • default (defaults to: :__block)

    an object to return if timezone is not found

Yields:

  • the block to run if the timezone is not found

Yield Parameters:

  • name (String)

    the timezone name if the timezone is not found

Returns:

  • (Timezone::Zone)

    if the timezone is found

  • (Object)

    if the timezone is not found and a default value or block has been provided

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/timezone.rb', line 42

def self.fetch(name, default = :__block, &block)
  return ::Timezone::Zone.new(name) if Loader.valid?(name)

  if block_given? && default != :__block
    warn('warning: block supersedes default value argument')
  end

  return block.call(name) if block_given?
  return default unless default == :__block

  raise ::Timezone::Error::InvalidZone
end

.lookup(lat, long, default = :__block) {|name| ... } ⇒ Timezone::Zone, Object

Lookup a timezone name by (lat, long) and then fetch the timezone object.

Parameters:

  • lat (Double)

    the latitude coordinate

  • long (Double)

    the longitude coordinate

  • default (defaults to: :__block)

    an optional object to return if the remote lookup succeeds but the timezone is not found

Yields:

  • the block to run if the remote lookup succeeds and the timezone is not found

Yield Parameters:

  • name (String)

    the timezone name if the remote lookup succeeds and the timezone is not found

Returns:

  • (Timezone::Zone)

    if the remote lookup succeeds and the timezone is found

  • (Object)

    if the remote lookup succeeds, the timezone is not found, and a default value or block has been provided

Raises:



76
77
78
# File 'lib/timezone.rb', line 76

def self.lookup(lat, long, default = :__block, &block)
  fetch(::Timezone::Lookup.lookup.lookup(lat, long), default, &block)
end

.namesArray<String>

A list of all timezone names.

Returns:

  • (Array<String>)

    all the timezone names



13
14
15
# File 'lib/timezone.rb', line 13

def self.names
  Loader.names
end