Class: TZInfo::TimezoneTransitionInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb

Overview

Represents an offset defined in a Timezone data file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset, previous_offset, numerator_or_time, denominator = nil) ⇒ TimezoneTransitionInfo

Creates a new TimezoneTransitionInfo with the given offset, previous_offset (both TimezoneOffsetInfo instances) and UTC time. if denominator is nil, numerator_or_time is treated as a number of seconds since the epoch. If denominator is specified numerator_or_time and denominator are used to create a DateTime as follows:

DateTime.new!(Rational.send(:new!, numerator_or_time, denominator), 0, Date::ITALY)

For performance reasons, the numerator and denominator must be specified in their lowest form.


55
56
57
58
59
60
61
62
63
64
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 55

def initialize(offset, previous_offset, numerator_or_time, denominator = nil)
  @offset = offset
  @previous_offset = previous_offset
  @numerator_or_time = numerator_or_time
  @denominator = denominator
  
  @at = nil
  @local_end = nil
  @local_start = nil
end

Instance Attribute Details

#offsetObject (readonly)

The offset this transition changes to (a TimezoneOffsetInfo instance).


30
31
32
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 30

def offset
  @offset
end

#previous_offsetObject (readonly)

The offset this transition changes from (a TimezoneOffsetInfo instance).


33
34
35
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 33

def previous_offset
  @previous_offset
end

Instance Method Details

#==(tti) ⇒ Object

Returns true if this TimezoneTransitionInfo is equal to the given TimezoneTransitionInfo. Two TimezoneTransitionInfo instances are considered to be equal by == if offset, previous_offset and at are all equal.


101
102
103
104
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 101

def ==(tti)
  tti.respond_to?(:offset) && tti.respond_to?(:previous_offset) && tti.respond_to?(:at) &&
    offset == tti.offset && previous_offset == tti.previous_offset && at == tti.at
end

#atObject

A TimeOrDateTime instance representing the UTC time when this transition occurs.


68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 68

def at
  unless @at
    unless @denominator 
      @at = TimeOrDateTime.new(@numerator_or_time)
    else
      r = RubyCoreSupport.rational_new!(@numerator_or_time, @denominator)
      dt = RubyCoreSupport.datetime_new!(r, 0, Date::ITALY)
      @at = TimeOrDateTime.new(dt)
    end
  end
  
  @at
end

#eql?(tti) ⇒ Boolean

Returns true if this TimezoneTransitionInfo is equal to the given TimezoneTransitionInfo. Two TimezoneTransitionInfo instances are considered to be equal by eql? if offset, previous_offset, numerator_or_time and denominator are all equal. This is stronger than ==, which just requires the at times to be equal regardless of how they were originally specified.

Returns:

  • (Boolean)

112
113
114
115
116
117
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 112

def eql?(tti)
  tti.respond_to?(:offset) && tti.respond_to?(:previous_offset) &&
    tti.respond_to?(:numerator_or_time) && tti.respond_to?(:denominator) &&
    offset == tti.offset && previous_offset == tti.previous_offset &&
    numerator_or_time == tti.numerator_or_time && denominator == tti.denominator        
end

#hashObject

Returns a hash of this TimezoneTransitionInfo instance.


120
121
122
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 120

def hash
  @offset.hash ^ @previous_offset.hash ^ @numerator_or_time.hash ^ @denominator.hash
end

#inspectObject

Returns internal object state as a programmer-readable string.


125
126
127
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 125

def inspect
  "#<#{self.class}: #{at.inspect},#{@offset.inspect}>"      
end

#local_endObject

A TimeOrDateTime instance representing the local time when this transition causes the previous observance to end (calculated from at using previous_offset).


85
86
87
88
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 85

def local_end
  @local_end = at.add_with_convert(@previous_offset.utc_total_offset) unless @local_end      
  @local_end
end

#local_startObject

A TimeOrDateTime instance representing the local time when this transition causes the next observance to start (calculated from at using offset).


92
93
94
95
# File 'lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb', line 92

def local_start
  @local_start = at.add_with_convert(@offset.utc_total_offset) unless @local_start
  @local_start
end