module Sequel::NamedTimezones

Constants

BROKEN_TIME_AT_WITH_NSEC

Whether Time.at with :nsec and :in is broken. True on JRuby < 9.3.9.0.

Attributes

tzinfo_disambiguator[RW]

Handles TZInfo::AmbiguousTime exceptions automatically by providing a proc called with both the datetime value being converted as well as the array of TZInfo::TimezonePeriod results. Example:

Sequel.tzinfo_disambiguator = proc{|datetime, periods| periods.first}

Private Instance Methods

convert_input_time_other(v, input_timezone) click to toggle source

Convert the given input Time (which must be in UTC) to the given input timezone, which should be a TZInfo::Timezone instance.

# File lib/sequel/extensions/named_timezones.rb, line 76
def convert_input_time_other(v, input_timezone)
  Time.new(v.year, v.mon, v.day, v.hour, v.min, (v.sec + Rational(v.nsec, 1000000000)), input_timezone)
rescue TZInfo::AmbiguousTime
  raise unless disamb = tzinfo_disambiguator_for(v)
  period = input_timezone.period_for_local(v, &disamb)
  offset = period.utc_total_offset
  # :nocov:
  if BROKEN_TIME_AT_WITH_NSEC
    Time.at(v.to_i - offset, :in => input_timezone) + v.nsec/1000000000.0
  # :nocov:
  else
    Time.at(v.to_i - offset, v.nsec, :nsec, :in => input_timezone)
  end
end
convert_output_time_other(v, output_timezone) click to toggle source

Convert the given input Time to the given output timezone, which should be a TZInfo::Timezone instance.

# File lib/sequel/extensions/named_timezones.rb, line 93
def convert_output_time_other(v, output_timezone)
  # :nocov:
  if BROKEN_TIME_AT_WITH_NSEC
    Time.at(v.to_i, :in => output_timezone) + v.nsec/1000000000.0
  # :nocov:
  else
    Time.at(v.to_i, v.nsec, :nsec, :in => output_timezone)
  end
end