class TZInfo::DataSources::TransitionsDataTimezoneInfo
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/tzinfo/data_sources/transitions_data_timezone_info.rbs class TZInfo::DataSources::TransitionsDataTimezoneInfo < TZInfo::DataSources::DataTimezoneInfo def find_minimum_transition: () -> untyped def find_minimum_transition: () -> untyped def initialize: (String identifier, Array[TZInfo::TimezoneTransition] transitions) -> void def period_for: (TZInfo::Timestamp timestamp) -> untyped end
the locally observed time.
Represents a data time zone defined by a list of transitions that change
def find_minimum_transition(&block)
Experimental RBS support (using type sampling data from the type_fusion
project).
def find_minimum_transition: () -> untyped
This signature was generated using 42 samples from 1 application.
-
(Integer)
- the index of the earliest transition safisfying
Other tags:
- Yieldreturn: - `true` for the earliest transition that
Other tags:
- Yieldparam: transition - a {TimezoneTransition}
Other tags:
- Yield: - the caller will be yielded to to test the search
def find_minimum_transition(&block) @transitions.bsearch_index(&block) end
def find_minimum_transition
Experimental RBS support (using type sampling data from the type_fusion
project).
def find_minimum_transition: () -> untyped
This signature was generated using 42 samples from 1 application.
-
(Integer)
- the index of the earliest transition safisfying
Other tags:
- Yieldreturn: - `true` for the earliest transition that
Other tags:
- Yieldparam: transition - a {TimezoneTransition}
Other tags:
- Yield: - the caller will be yielded to to test the search
def find_minimum_transition # A Ruby implementation of the find-minimum mode of Array#bsearch_index. low = 0 high = @transitions.length satisfied = false while low < high do mid = (low + high).div(2) if yield @transitions[mid] satisfied = true high = mid else low = mid + 1 end end satisfied ? low : nil end
def initialize(identifier, transitions)
Experimental RBS support (using type sampling data from the type_fusion
project).
def initialize: (String identifier, (TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition | TZInfo::TimezoneTransition) transitions) -> void
This signature was generated using 3 samples from 1 application.
-
(ArgumentError)
- if `transitions` is an empty `Array`. -
(ArgumentError)
- if `transitions` is `nil`. -
(ArgumentError)
- if `identifier` is `nil`.
Parameters:
-
transitions
(Array
) -- an `Array` of -
identifier
(String
) -- the identifier of the time zone.
def initialize(identifier, transitions) super(identifier) raise ArgumentError, 'transitions must be specified' unless transitions raise ArgumentError, 'transitions must not be an empty Array' if transitions.empty? @transitions = transitions.freeze end
def period_for(timestamp)
Experimental RBS support (using type sampling data from the type_fusion
project).
def period_for: (TZInfo::Timestamp timestamp) -> untyped
This signature was generated using 30 samples from 1 application.
def period_for(timestamp) raise ArgumentError, 'timestamp must be specified' unless timestamp raise ArgumentError, 'timestamp must have a specified utc_offset' unless timestamp.utc_offset timestamp_value = timestamp.value index = find_minimum_transition {|t| t.timestamp_value >= timestamp_value } if index transition = @transitions[index] if transition.timestamp_value == timestamp_value # timestamp occurs within the second of the found transition, so is # the transition that starts the period. start_transition = transition end_transition = @transitions[index + 1] else # timestamp occurs before the second of the found transition, so is # the transition that ends the period. start_transition = index == 0 ? nil : @transitions[index - 1] end_transition = transition end else start_transition = @transitions.last end_transition = nil end TransitionsTimezonePeriod.new(start_transition, end_transition) end
def periods_for_local(local_timestamp)
def periods_for_local(local_timestamp) raise ArgumentError, 'local_timestamp must be specified' unless local_timestamp raise ArgumentError, 'local_timestamp must have an unspecified utc_offset' if local_timestamp.utc_offset local_timestamp_value = local_timestamp.value latest_possible_utc_value = local_timestamp_value + 86400 earliest_possible_utc_value = local_timestamp_value - 86400 # Find the index of the first transition that occurs after a latest # possible UTC representation of the local timestamp and then search # backwards until an earliest possible UTC representation. index = find_minimum_transition {|t| t.timestamp_value >= latest_possible_utc_value } # No transitions after latest_possible_utc_value, set to max index + 1 # to search backwards including the period after the last transition index = @transitions.length unless index result = [] index.downto(0) do |i| start_transition = i > 0 ? @transitions[i - 1] : nil end_transition = @transitions[i] offset = start_transition ? start_transition.offset : end_transition.previous_offset utc_timestamp_value = local_timestamp_value - offset.observed_utc_offset # It is not necessary to compare the sub-seconds because a timestamp # is in the period if is >= the start transition (sub-seconds would # make == become >) and if it is < the end transition (which # sub-seconds cannot affect). if (!start_transition || utc_timestamp_value >= start_transition.timestamp_value) && (!end_transition || utc_timestamp_value < end_transition.timestamp_value) result << TransitionsTimezonePeriod.new(start_transition, end_transition) elsif end_transition && end_transition.timestamp_value < earliest_possible_utc_value break end end result.reverse! end
def transition_on_or_after_timestamp?(transition, timestamp)
-
(Boolean)
- `true` if `transition` occurs at or after `timestamp`,
Parameters:
-
timestamp
(Timestamp
) -- the timestamp to compare. -
transition
(TimezoneTransition
) -- the transition to compare.
def transition_on_or_after_timestamp?(transition, timestamp) transition_timestamp_value = transition.timestamp_value timestamp_value = timestamp.value transition_timestamp_value > timestamp_value || transition_timestamp_value == timestamp_value && timestamp.sub_second == 0 end
def transitions_up_to(to_timestamp, from_timestamp = nil)
def transitions_up_to(to_timestamp, from_timestamp = nil) raise ArgumentError, 'to_timestamp must be specified' unless to_timestamp raise ArgumentError, 'to_timestamp must have a specified utc_offset' unless to_timestamp.utc_offset if from_timestamp raise ArgumentError, 'from_timestamp must have a specified utc_offset' unless from_timestamp.utc_offset raise ArgumentError, 'to_timestamp must be greater than from_timestamp' if to_timestamp <= from_timestamp end if from_timestamp from_index = find_minimum_transition {|t| transition_on_or_after_timestamp?(t, from_timestamp) } return [] unless from_index else from_index = 0 end to_index = find_minimum_transition {|t| transition_on_or_after_timestamp?(t, to_timestamp) } if to_index return [] if to_index < 1 to_index -= 1 else to_index = -1 end @transitions[from_index..to_index] end