Class: TZInfo::TimezoneTransitionInfo
- Inherits:
-
Object
- Object
- TZInfo::TimezoneTransitionInfo
- Defined in:
- lib/tzinfo/timezone_transition_info.rb
Overview
Represents an transition from one timezone offset to another at a particular date and time.
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
The offset this transition changes to (a TimezoneOffsetInfo instance).
-
#previous_offset ⇒ Object
readonly
The offset this transition changes from (a TimezoneOffsetInfo instance).
Instance Method Summary collapse
-
#==(tti) ⇒ Object
Returns true if this TimezoneTransitionInfo is equal to the given TimezoneTransitionInfo.
-
#at ⇒ Object
A TimeOrDateTime instance representing the UTC time when this transition occurs.
-
#eql?(tti) ⇒ Boolean
Returns true if this TimezoneTransitionInfo is equal to the given TimezoneTransitionInfo.
-
#hash ⇒ Object
Returns a hash of this TimezoneTransitionInfo instance.
-
#initialize(offset, previous_offset, numerator_or_timestamp, denominator_or_numerator = nil, denominator = nil) ⇒ TimezoneTransitionInfo
constructor
Creates a new TimezoneTransitionInfo with the given offset, previous_offset (both TimezoneOffsetInfo instances) and UTC time.
-
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
-
#local_end ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the previous observance to end (calculated from at using previous_offset).
-
#local_start ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the next observance to start (calculated from at using offset).
Constructor Details
#initialize(offset, previous_offset, numerator_or_timestamp, denominator_or_numerator = nil, denominator = nil) ⇒ TimezoneTransitionInfo
Creates a new TimezoneTransitionInfo with the given offset, previous_offset (both TimezoneOffsetInfo instances) and UTC time.
The time can be specified as a timestamp, as a rational to create a DateTime or as both.
If both a timestamp and rational are given, then the rational will only be used if the timestamp falls outside of the range of Time on the platform being used at runtime.
DateTimes are created from the rational as follows:
RubyCoreSupport.datetime_new!(RubyCoreSupport.rational_new!(numerator_or_time, denominator), 0, Date::ITALY)
For performance reasons, the numerator and denominator must be specified in their lowest form.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 61 def initialize(offset, previous_offset, , denominator_or_numerator = nil, denominator = nil) @offset = offset @previous_offset = previous_offset if denominator numerator = denominator_or_numerator = elsif denominator_or_numerator numerator = denominator = denominator_or_numerator = nil else numerator = nil denominator = nil = end # Determine whether to use the timestamp or the numerator and denominator. if numerator && ( ! || ( < 0 && !RubyCoreSupport.time_supports_negative) || (( < -2147483648 || > 2147483647) && !RubyCoreSupport.time_supports_64bit) ) @numerator_or_time = numerator @denominator = denominator else @numerator_or_time = @denominator = nil end @at = nil @local_end = nil @local_start = nil end |
Instance Attribute Details
#offset ⇒ Object (readonly)
The offset this transition changes to (a TimezoneOffsetInfo instance).
30 31 32 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 30 def offset @offset end |
#previous_offset ⇒ Object (readonly)
The offset this transition changes from (a TimezoneOffsetInfo instance).
33 34 35 |
# File 'lib/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.
132 133 134 135 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 132 def ==(tti) tti.kind_of?(TimezoneTransitionInfo) && offset == tti.offset && previous_offset == tti.previous_offset && at == tti.at end |
#at ⇒ Object
A TimeOrDateTime instance representing the UTC time when this transition occurs.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 99 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.
143 144 145 146 147 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 143 def eql?(tti) tti.kind_of?(TimezoneTransitionInfo) && offset == tti.offset && previous_offset == tti.previous_offset && numerator_or_time == tti.numerator_or_time && denominator == tti.denominator end |
#hash ⇒ Object
Returns a hash of this TimezoneTransitionInfo instance.
150 151 152 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 150 def hash @offset.hash ^ @previous_offset.hash ^ @numerator_or_time.hash ^ @denominator.hash end |
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
155 156 157 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 155 def inspect "#<#{self.class}: #{at.inspect},#{@offset.inspect}>" end |
#local_end ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the previous observance to end (calculated from at using previous_offset).
116 117 118 119 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 116 def local_end @local_end = at.add_with_convert(@previous_offset.utc_total_offset) unless @local_end @local_end end |
#local_start ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the next observance to start (calculated from at using offset).
123 124 125 126 |
# File 'lib/tzinfo/timezone_transition_info.rb', line 123 def local_start @local_start = at.add_with_convert(@offset.utc_total_offset) unless @local_start @local_start end |