Class: TZInfo::TimezoneTransition
- Inherits:
-
Object
- Object
- TZInfo::TimezoneTransition
- Defined in:
- lib/tzinfo/timezone_transition.rb
Overview
Represents a transition from one observed UTC offset (TimezoneOffset to another for a time zone.
Instance Attribute Summary collapse
-
#offset ⇒ TimezoneOffset
readonly
The offset this transition changes to.
-
#previous_offset ⇒ TimezoneOffset
readonly
The offset this transition changes from.
-
#timestamp_value ⇒ Integer
readonly
When this transition occurs as an
Integer
number of seconds since 1970-01-01 00:00:00 UTC ignoring leap seconds (i.e. each day is treated as if it were 86,400 seconds long).
Instance Method Summary collapse
-
#==(tti) ⇒ Boolean
(also: #eql?)
Determines if this TimezoneTransition is equal to another instance.
-
#at ⇒ Timestamp
Returns a Timestamp instance representing the UTC time when this transition occurs.
-
#hash ⇒ Integer
A hash based on #offset, #previous_offset and #timestamp_value.
-
#initialize(offset, previous_offset, timestamp_value) ⇒ TimezoneTransition
constructor
Initializes a new TimezoneTransition.
-
#local_end_at ⇒ TimestampWithOffset
Returns a TimestampWithOffset instance representing the local time when this transition causes the previous observance to end (calculated from #at using #previous_offset).
-
#local_start_at ⇒ TimestampWithOffset
Returns a TimestampWithOffset 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, timestamp_value) ⇒ TimezoneTransition
Initializes a new TZInfo::TimezoneTransition.
TZInfo::TimezoneTransition instances should not normally be constructed manually.
34 35 36 37 38 |
# File 'lib/tzinfo/timezone_transition.rb', line 34 def initialize(offset, previous_offset, ) @offset = offset @previous_offset = previous_offset = end |
Instance Attribute Details
#offset ⇒ TimezoneOffset (readonly)
Returns the offset this transition changes to.
9 10 11 |
# File 'lib/tzinfo/timezone_transition.rb', line 9 def offset @offset end |
#previous_offset ⇒ TimezoneOffset (readonly)
Returns the offset this transition changes from.
12 13 14 |
# File 'lib/tzinfo/timezone_transition.rb', line 12 def previous_offset @previous_offset end |
#timestamp_value ⇒ Integer (readonly)
When this transition occurs as an Integer
number of seconds since
1970-01-01 00:00:00 UTC ignoring leap seconds (i.e. each day is treated as
if it were 86,400 seconds long). Equivalent to the result of calling the
value method on the TZInfo::Timestamp returned by #at.
21 22 23 |
# File 'lib/tzinfo/timezone_transition.rb', line 21 def end |
Instance Method Details
#==(tti) ⇒ Boolean Also known as: eql?
Determines if this TZInfo::TimezoneTransition is equal to another instance.
86 87 88 89 |
# File 'lib/tzinfo/timezone_transition.rb', line 86 def ==(tti) tti.kind_of?(TimezoneTransition) && offset == tti.offset && previous_offset == tti.previous_offset && == tti. end |
#at ⇒ Timestamp
Returns a TZInfo::Timestamp instance representing the UTC time when this transition occurs.
To obtain the result as a Time
or DateTime
, call either
to_time or to_datetime on the
TZInfo::Timestamp instance that is returned.
48 49 50 |
# File 'lib/tzinfo/timezone_transition.rb', line 48 def at Timestamp.utc() end |
#hash ⇒ Integer
Returns a hash based on #offset, #previous_offset and #timestamp_value.
94 95 96 |
# File 'lib/tzinfo/timezone_transition.rb', line 94 def hash [@offset, @previous_offset, ].hash end |
#local_end_at ⇒ TimestampWithOffset
Returns a TZInfo::TimestampWithOffset instance representing the local time when this transition causes the previous observance to end (calculated from #at using #previous_offset).
To obtain the result as a Time
or DateTime
, call either
to_time or to_datetime on the TZInfo::TimestampWithOffset instance that is returned.
62 63 64 |
# File 'lib/tzinfo/timezone_transition.rb', line 62 def local_end_at TimestampWithOffset.new(, 0, @previous_offset.observed_utc_offset).set_timezone_offset(@previous_offset) end |
#local_start_at ⇒ TimestampWithOffset
Returns a TZInfo::TimestampWithOffset instance representing the local time when this transition causes the next observance to start (calculated from #at using #offset).
To obtain the result as a Time
or DateTime
, call either
to_time or to_datetime on the TZInfo::TimestampWithOffset instance that is returned.
76 77 78 |
# File 'lib/tzinfo/timezone_transition.rb', line 76 def local_start_at TimestampWithOffset.new(, 0, @offset.observed_utc_offset).set_timezone_offset(@offset) end |