Class: TZInfo::Format2::TimezoneDefiner
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/timezone_definer.rb
Overview
Instances of TimezoneDefiner are yielded to TZInfo::Data modules by TimezoneDefinition to allow the offsets and transitions of the time zone to be specified.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#transitions ⇒ Array<TimezoneTransition>
readonly
The defined transitions of the time zone.
Instance Method Summary collapse
-
#first_offset ⇒ TimezoneOffset
Returns the first offset to be defined or ‘nil` if no offsets have been defined.
-
#initialize(string_deduper) ⇒ TimezoneDefiner
constructor
Initializes a new TimezoneDefiner.
-
#offset(id, base_utc_offset, std_offset, abbreviation) ⇒ Object
Defines an offset.
-
#subsequent_rules(*args) ⇒ Object
Defines the rules that will be used for handling instants after the last transition.
-
#transition(offset_id, timestamp_value) ⇒ Object
Defines a transition to a given offset.
Constructor Details
#initialize(string_deduper) ⇒ TimezoneDefiner
Initializes a new TimezoneDefiner.
20 21 22 23 24 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/timezone_definer.rb', line 20 def initialize(string_deduper) @string_deduper = string_deduper @offsets = {} @transitions = [] end |
Instance Attribute Details
#transitions ⇒ Array<TimezoneTransition> (readonly)
Returns the defined transitions of the time zone.
14 15 16 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/timezone_definer.rb', line 14 def transitions @transitions end |
Instance Method Details
#first_offset ⇒ TimezoneOffset
Returns the first offset to be defined or ‘nil` if no offsets have been
defined. The first offset is observed before the time of the first
transition.
32 33 34 35 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/timezone_definer.rb', line 32 def first_offset first = @offsets.first first && first.last end |
#offset(id, base_utc_offset, std_offset, abbreviation) ⇒ Object
Defines an offset.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/timezone_definer.rb', line 49 def offset(id, base_utc_offset, std_offset, abbreviation) raise ArgumentError, 'An offset has already been defined with the given id' if @offsets.has_key?(id) # Dedupe non-frozen literals from format 1 on all Ruby versions and # format 2 on Ruby < 2.3 (without frozen_string_literal support). abbreviation = @string_deduper.dedupe(abbreviation) offset = TimezoneOffset.new(base_utc_offset, std_offset, abbreviation) @offsets[id] = offset @previous_offset ||= offset end |
#subsequent_rules(*args) ⇒ Object
Defines the rules that will be used for handling instants after the last transition.
This method is currently just a placeholder for forward compatibility that accepts and ignores any arguments passed.
Support for subsequent rules will be added in a future version of TZInfo and the rules will be included in format 2 releases of TZInfo::Data.
90 91 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/timezone_definer.rb', line 90 def subsequent_rules(*args) end |
#transition(offset_id, timestamp_value) ⇒ Object
Defines a transition to a given offset.
Transitions must be defined in increasing time order.
74 75 76 77 78 79 80 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tzinfo-2.0.5/lib/tzinfo/format2/timezone_definer.rb', line 74 def transition(offset_id, ) offset = @offsets[offset_id] raise ArgumentError, 'offset_id has not been defined' unless offset raise ArgumentError, 'timestamp is not greater than the timestamp of the previously defined transition' if !@transitions.empty? && @transitions.last. >= @transitions << TimezoneTransition.new(offset, @previous_offset, ) @previous_offset = offset end |