module Sequel::NamedTimezones

simplecov:enable

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
79 def convert_input_time_other(v, input_timezone)
80   Time.new(v.year, v.mon, v.day, v.hour, v.min, (v.sec + Rational(v.nsec, 1000000000)), input_timezone)
81 rescue TZInfo::AmbiguousTime
82   raise unless disamb = tzinfo_disambiguator_for(v)
83   period = input_timezone.period_for_local(v, &disamb)
84   offset = period.utc_total_offset
85   # simplecov:disable
86   if BROKEN_TIME_AT_WITH_NSEC
87     Time.at(v.to_i - offset, :in => input_timezone) + v.nsec/1000000000.0
88   # simplecov:enable
89   else
90     Time.at(v.to_i - offset, v.nsec, :nsec, :in => input_timezone)
91   end
92 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
 96 def convert_output_time_other(v, output_timezone)
 97   # simplecov:disable
 98   if BROKEN_TIME_AT_WITH_NSEC
 99     Time.at(v.to_i, :in => output_timezone) + v.nsec/1000000000.0
100   # simplecov:enable
101   else
102     Time.at(v.to_i, v.nsec, :nsec, :in => output_timezone)
103   end
104 end