123456789_123456789_123456789_123456789_123456789_

Class: TZInfo::CountryTimezone

Relationships & Source Files
Inherits: Object
Defined in: lib/tzinfo/country_timezone.rb

Overview

Information about a time zone used by a Country.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(identifier, latitude, longitude, description = nil) ⇒ CountryTimezone

Creates a new CountryTimezone.

The passed in identifier and description instances will be frozen.

CountryTimezone instances should normally only be constructed by implementations of DataSource.

Parameters:

  • identifier (String)

    the Timezone identifier.

  • latitude (Rational)

    the latitude of the time zone.

  • longitude (Rational)

    the longitude of the time zone.

  • description (String) (defaults to: nil)

    an optional description of the time zone.

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 44

def initialize(identifier, latitude, longitude, description = nil)
  @identifier = identifier.freeze
  @latitude = latitude
  @longitude = longitude
  @description = description && description.freeze
end

Instance Attribute Details

#descriptionString (readonly)

A description of this time zone in relation to the country, e.g. "Eastern Time". This is usually nil for countries that have a single time zone.

Returns:

  • (String)

    an optional description of the time zone.

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 31

attr_reader :description

#identifierString (readonly)

Returns:

  • (String)

    the identifier of the Timezone being described.

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 7

attr_reader :identifier

#latitudeRational (readonly)

The latitude of this time zone in degrees. Positive numbers are degrees north and negative numbers are degrees south.

Note that depending on the data source, the position given by #latitude and #longitude may not be within the country.

Returns:

  • (Rational)

    the latitude in degrees.

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 16

attr_reader :latitude

#longitudeRational (readonly)

The longitude of this time zone in degrees. Positive numbers are degrees east and negative numbers are degrees west.

Note that depending on the data source, the position given by #latitude and #longitude may not be within the country.

Returns:

  • (Rational)

    the longitude in degrees.

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 25

attr_reader :longitude

Instance Method Details

#==(ct) ⇒ TrueClass

Tests if the given object is equal to the current instance (has the same identifier, latitude, longitude and description).

Parameters:

  • ct (Object)

    the object to be compared.

Returns:

  • (TrueClass)

    true if ct is equal to the current instance.

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 72

def ==(ct)
  ct.kind_of?(CountryTimezone) &&
    identifier == ct.identifier  && latitude == ct.latitude &&
    longitude == ct.longitude   && description == ct.description
end

#description_or_friendly_identifierString

Returns:

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 63

def description_or_friendly_identifier
  description || timezone.friendly_identifier(true)
end

#eql?(ct) ⇒ Boolean

Tests if the given object is equal to the current instance (has the same identifier, latitude, longitude and description).

Parameters:

  • ct (Object)

    the object to be compared.

Returns:

  • (Boolean)

    true if ct is equal to the current instance.

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 83

def eql?(ct)
  self == ct
end

#hashInteger

Returns:

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 89

def hash
  [@identifier, @latitude, @longitude, @description].hash
end

#timezoneTimezone

Returns the associated Timezone.

The result is actually an instance of TimezoneProxy in order to defer loading of the time zone transition data until it is first needed.

Returns:

[ GitHub ]

  
# File 'lib/tzinfo/country_timezone.rb', line 57

def timezone
  Timezone.get_proxy(@identifier)
end