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
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
Source
# File lib/sequel/extensions/named_timezones.rb 77 def convert_input_time_other(v, input_timezone) 78 Time.new(v.year, v.mon, v.day, v.hour, v.min, (v.sec + Rational(v.nsec, 1000000000)), input_timezone) 79 rescue TZInfo::AmbiguousTime 80 raise unless disamb = tzinfo_disambiguator_for(v) 81 period = input_timezone.period_for_local(v, &disamb) 82 offset = period.utc_total_offset 83 # :nocov: 84 if BROKEN_TIME_AT_WITH_NSEC 85 Time.at(v.to_i - offset, :in => input_timezone) + v.nsec/1000000000.0 86 # :nocov: 87 else 88 Time.at(v.to_i - offset, v.nsec, :nsec, :in => input_timezone) 89 end 90 end
Convert the given input Time (which must be in UTC) to the given input timezone, which should be a TZInfo::Timezone instance.
Source
# File lib/sequel/extensions/named_timezones.rb 94 def convert_output_time_other(v, output_timezone) 95 # :nocov: 96 if BROKEN_TIME_AT_WITH_NSEC 97 Time.at(v.to_i, :in => output_timezone) + v.nsec/1000000000.0 98 # :nocov: 99 else 100 Time.at(v.to_i, v.nsec, :nsec, :in => output_timezone) 101 end 102 end
Convert the given input Time to the given output timezone, which should be a TZInfo::Timezone instance.