Class: TZInfo::CountryTimezone

Inherits:
Object
  • Object
show all
Defined in:
lib/tzinfo/country_timezone.rb

Overview

A Timezone within a Country. This contains extra information about the Timezone that is specific to the Country (a Timezone could be used by multiple countries).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject (readonly)

A description of this timezone in relation to the country, e.g. “Eastern Time”. This is usually nil for countries having only a single Timezone.



12
13
14
# File 'lib/tzinfo/country_timezone.rb', line 12

def description
  @description
end

#identifierObject (readonly)

The zone identifier.



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

def identifier
  @identifier
end

Class Method Details

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

Creates a new CountryTimezone with a timezone identifier, latitude, longitude and description. The latitude and longitude must be specified as instances of Rational.

CountryTimezone instances should normally only be constructed when creating new DataSource implementations.



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

def new(identifier, latitude, longitude, description = nil)
  super(identifier, latitude, nil, longitude, nil, description)      
end

Instance Method Details

#==(ct) ⇒ Object

Returns true if and only if the given CountryTimezone is equal to the current CountryTimezone (has the same identifer, latitude, longitude and description).



109
110
111
112
113
# File 'lib/tzinfo/country_timezone.rb', line 109

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

#description_or_friendly_identifierObject

if description is not nil, this method returns description; otherwise it returns timezone.friendly_identifier(true).



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

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

#eql?(ct) ⇒ Boolean

Returns true if and only if the given CountryTimezone is equal to the current CountryTimezone (has the same identifer, latitude, longitude and description).

Returns:

  • (Boolean)


118
119
120
# File 'lib/tzinfo/country_timezone.rb', line 118

def eql?(ct)
  self == ct
end

#hashObject

Returns a hash of this CountryTimezone.



123
124
125
126
127
128
# File 'lib/tzinfo/country_timezone.rb', line 123

def hash
  @identifier.hash ^ 
    (@latitude ? @latitude.numerator.hash ^ @latitude.denominator.hash : @latitude_numerator.hash ^ @latitude_denominator.hash) ^
    (@longitude ? @longitude.numerator.hash ^ @longitude.denominator.hash : @longitude_numerator.hash ^ @longitude_denominator.hash) ^
    @description.hash
end

#inspectObject

Returns internal object state as a programmer-readable string.



131
132
133
# File 'lib/tzinfo/country_timezone.rb', line 131

def inspect
  "#<#{self.class}: #@identifier>"
end

#latitudeObject

The latitude of this timezone in degrees as a Rational.



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tzinfo/country_timezone.rb', line 77

def latitude
  # Thread-safety: It is possible that the value of @latitude may be 
  # calculated multiple times in concurrently executing threads. It is not 
  # worth the overhead of locking to ensure that @latitude is only 
  # calculated once.
  unless @latitude
     result = RubyCoreSupport.rational_new!(@latitude_numerator, @latitude_denominator)
     return result if frozen?
     @latitude = result
  end

  @latitude
end

#longitudeObject

The longitude of this timezone in degrees as a Rational.



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/tzinfo/country_timezone.rb', line 92

def longitude
  # Thread-safety: It is possible that the value of @longitude may be 
  # calculated multiple times in concurrently executing threads. It is not 
  # worth the overhead of locking to ensure that @longitude is only 
  # calculated once.
  unless @longitude
    result = RubyCoreSupport.rational_new!(@longitude_numerator, @longitude_denominator)
    return result if frozen?
    @longitude = result
  end

  @longitude
end

#timezoneObject

The Timezone (actually a TimezoneProxy for performance reasons).



66
67
68
# File 'lib/tzinfo/country_timezone.rb', line 66

def timezone
  Timezone.get_proxy(@identifier)
end