module Sequel::NamedTimezones
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 73 def convert_input_time_other(v, input_timezone) 74 Time.new(v.year, v.mon, v.day, v.hour, v.min, (v.sec + Rational(v.nsec, 1000000000)), input_timezone) 75 rescue TZInfo::AmbiguousTime 76 raise unless disamb = tzinfo_disambiguator_for(v) 77 period = input_timezone.period_for_local(v, &disamb) 78 offset = period.utc_total_offset 79 # :nocov: 80 if defined?(JRUBY_VERSION) 81 Time.at(v.to_i - offset, :in => input_timezone) + v.nsec/1000000000.0 82 # :nocov: 83 else 84 Time.at(v.to_i - offset, v.nsec, :nsec, :in => input_timezone) 85 end 86 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 90 def convert_output_time_other(v, output_timezone) 91 # :nocov: 92 if defined?(JRUBY_VERSION) 93 Time.at(v.to_i, :in => output_timezone) + v.nsec/1000000000.0 94 # :nocov: 95 else 96 Time.at(v.to_i, v.nsec, :nsec, :in => output_timezone) 97 end 98 end