class TZInfo::Timezone

def offsets_up_to(to, from = nil)

Raises:
  • (ArgumentError) - if either `to` or `from` is a {Timestamp} with an
  • (ArgumentError) - is raised if `to` is `nil`.
  • (ArgumentError) - if `from` is specified and `to` is not greater than

Returns:
  • (Array) - the offsets that are used earlier than

Parameters:
  • from (Object) -- an optional `Time`, `DateTime` or {Timestamp}
  • to (Object) -- a `Time`, `DateTime` or {Timestamp} specifying the
def offsets_up_to(to, from = nil)
  raise ArgumentError, 'to must be specified' unless to
  to_timestamp = Timestamp.for(to)
  from_timestamp = from && Timestamp.for(from)
  transitions = transitions_up_to(to_timestamp, from_timestamp)
  if transitions.empty?
    # No transitions in the range, find the period that covers it.
    if from_timestamp
      # Use the from date as it is inclusive.
      period = period_for(from_timestamp)
    else
      # to is exclusive, so this can't be used with period_for. However, any
      # time earlier than to can be used. Subtract 1 hour.
      period = period_for(to_timestamp.add_and_set_utc_offset(-3600, :utc))
    end
    [period.offset]
  else
    result = Set.new
    first = transitions.first
    result << first.previous_offset unless from_timestamp && first.at == from_timestamp
    transitions.each do |t|
      result << t.offset
    end
    result.to_a
  end
end