Class: TZInfo::TimezoneTransition
- Inherits:
-
Object
- Object
- TZInfo::TimezoneTransition
- Defined in:
- lib/tzinfo/timezone_transition.rb
Overview
Represents a 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 TimezoneOffset instance).
-
#previous_offset ⇒ Object
readonly
The offset this transition changes from (a TimezoneOffset instance).
Instance Method Summary collapse
-
#==(tti) ⇒ Object
Returns true if this TimezoneTransition is equal to the given TimezoneTransition.
-
#at ⇒ Object
A TimeOrDateTime instance representing the UTC time when this transition occurs.
-
#datetime ⇒ Object
The UTC time when this transition occurs, returned as a DateTime instance.
-
#eql?(tti) ⇒ Boolean
Returns true if this TimezoneTransition is equal to the given TimezoneTransition.
-
#hash ⇒ Object
Returns a hash of this TimezoneTransition instance.
-
#initialize(offset, previous_offset) ⇒ TimezoneTransition
constructor
Initializes a new TimezoneTransition.
-
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
-
#local_end ⇒ Object
The local time when this transition causes the previous observance to end, returned as a DateTime instance.
-
#local_end_at ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the previous observance to end (calculated from at using previous_offset).
-
#local_end_time ⇒ Object
The local time when this transition causes the previous observance to end, returned as a Time instance.
-
#local_start ⇒ Object
The local time when this transition causes the next observance to start, returned as a DateTime instance.
-
#local_start_at ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the next observance to start (calculated from at using offset).
-
#local_start_time ⇒ Object
The local time when this transition causes the next observance to start, returned as a Time instance.
-
#time ⇒ Object
The UTC time when this transition occurs, returned as a Time instance.
Constructor Details
#initialize(offset, previous_offset) ⇒ TimezoneTransition
Initializes a new TimezoneTransition.
TimezoneTransition instances should not normally be constructed manually.
14 15 16 17 18 19 |
# File 'lib/tzinfo/timezone_transition.rb', line 14 def initialize(offset, previous_offset) @offset = offset @previous_offset = previous_offset @local_end_at = nil @local_start_at = nil end |
Instance Attribute Details
#offset ⇒ Object (readonly)
The offset this transition changes to (a TimezoneOffset instance).
6 7 8 |
# File 'lib/tzinfo/timezone_transition.rb', line 6 def offset @offset end |
#previous_offset ⇒ Object (readonly)
The offset this transition changes from (a TimezoneOffset instance).
9 10 11 |
# File 'lib/tzinfo/timezone_transition.rb', line 9 def previous_offset @previous_offset end |
Instance Method Details
#==(tti) ⇒ Object
Returns true if this TimezoneTransition is equal to the given TimezoneTransition. Two TimezoneTransition instances are considered to be equal by == if offset, previous_offset and at are all equal.
100 101 102 103 |
# File 'lib/tzinfo/timezone_transition.rb', line 100 def ==(tti) tti.kind_of?(TimezoneTransition) && 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.
23 24 25 |
# File 'lib/tzinfo/timezone_transition.rb', line 23 def at raise_not_implemented('at') end |
#datetime ⇒ Object
The UTC time when this transition occurs, returned as a DateTime instance.
28 29 30 |
# File 'lib/tzinfo/timezone_transition.rb', line 28 def datetime at.to_datetime end |
#eql?(tti) ⇒ Boolean
Returns true if this TimezoneTransition is equal to the given TimezoneTransition. Two TimezoneTransition instances are considered to be equal by eql? if offset, previous_offset and at are all equal and the type used to define at in both instances is the same.
109 110 111 112 |
# File 'lib/tzinfo/timezone_transition.rb', line 109 def eql?(tti) tti.kind_of?(TimezoneTransition) && offset == tti.offset && previous_offset == tti.previous_offset && at.eql?(tti.at) end |
#hash ⇒ Object
Returns a hash of this TimezoneTransition instance.
115 116 117 |
# File 'lib/tzinfo/timezone_transition.rb', line 115 def hash @offset.hash ^ @previous_offset.hash ^ at.hash end |
#inspect ⇒ Object
Returns internal object state as a programmer-readable string.
120 121 122 |
# File 'lib/tzinfo/timezone_transition.rb', line 120 def inspect "#<#{self.class}: #{at.inspect},#{@offset.inspect}>" end |
#local_end ⇒ Object
The local time when this transition causes the previous observance to end, returned as a DateTime instance.
57 58 59 |
# File 'lib/tzinfo/timezone_transition.rb', line 57 def local_end local_end_at.to_datetime end |
#local_end_at ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the previous observance to end (calculated from at using previous_offset).
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tzinfo/timezone_transition.rb', line 40 def local_end_at # Thread-safety: It is possible that the value of @local_end_at may be # calculated multiple times in concurrently executing threads. It is not # worth the overhead of locking to ensure that @local_end_at is only # calculated once. unless @local_end_at result = at.add_with_convert(@previous_offset.utc_total_offset) return result if frozen? @local_end_at = result end @local_end_at end |
#local_end_time ⇒ Object
The local time when this transition causes the previous observance to end, returned as a Time instance.
63 64 65 |
# File 'lib/tzinfo/timezone_transition.rb', line 63 def local_end_time local_end_at.to_time end |
#local_start ⇒ Object
The local time when this transition causes the next observance to start, returned as a DateTime instance.
86 87 88 |
# File 'lib/tzinfo/timezone_transition.rb', line 86 def local_start local_start_at.to_datetime end |
#local_start_at ⇒ Object
A TimeOrDateTime instance representing the local time when this transition causes the next observance to start (calculated from at using offset).
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tzinfo/timezone_transition.rb', line 69 def local_start_at # Thread-safety: It is possible that the value of @local_start_at may be # calculated multiple times in concurrently executing threads. It is not # worth the overhead of locking to ensure that @local_start_at is only # calculated once. unless @local_start_at result = at.add_with_convert(@offset.utc_total_offset) return result if frozen? @local_start_at = result end @local_start_at end |
#local_start_time ⇒ Object
The local time when this transition causes the next observance to start, returned as a Time instance.
92 93 94 |
# File 'lib/tzinfo/timezone_transition.rb', line 92 def local_start_time local_start_at.to_time end |
#time ⇒ Object
The UTC time when this transition occurs, returned as a Time instance.
33 34 35 |
# File 'lib/tzinfo/timezone_transition.rb', line 33 def time at.to_time end |