lib/et-orbi.rb in et-orbi-1.1.0 vs lib/et-orbi.rb in et-orbi-1.1.1

- old
+ new

@@ -5,11 +5,11 @@ require 'tzinfo' module EtOrbi - VERSION = '1.1.0' + VERSION = '1.1.1' # # module methods class << self @@ -45,11 +45,11 @@ #p [ :parse, :ltz, local_tzone ] zone = opts[:zone] || str_zone || find_olson_zone(str) || - local_tzone + determine_local_tzone #p [ :parse, :zone, zone ] str = str.sub(zone.name, '') unless zone.name.match(/\A[-+]/) # # for 'Sun Nov 18 16:01:00 Asia/Singapore 2012', @@ -141,11 +141,11 @@ def get_tzone(o) return o if o.is_a?(::TZInfo::Timezone) return nil if o == nil - return local_tzone if o == :local + return determine_local_tzone if o == :local return ::TZInfo::Timezone.get('Zulu') if o == 'Z' return o.tzinfo if o.respond_to?(:tzinfo) o = to_offset(o) if o.is_a?(Numeric) @@ -154,39 +154,21 @@ (@custom_tz_cache ||= {})[o] || get_offset_tzone(o) || (::TZInfo::Timezone.get(o) rescue nil) end - def local_tzone - - @local_tzone_tz ||= nil - @local_tzone_loaded_at ||= nil - - @local_tzone = nil \ - if @local_tzone_loaded_at && (Time.now > @local_tzone_loaded_at + 1800) - @local_tzone = nil \ - if @local_tzone_tz != ENV['TZ'] - - @local_tzone ||= - begin - @local_tzone_tz = ENV['TZ'] - @local_tzone_loaded_at = Time.now - determine_local_tzone - end - end - def render_nozone_time(seconds) t = Time.utc(0) + seconds ts = t.strftime('%Y-%m-%d %H:%M:%S') + ".#{(seconds % 1).to_s.split('.').last}" + tz = + EtOrbi.determine_local_tzone z = - EtOrbi.local_tzone ? - EtOrbi.local_tzone.period_for_local(t).abbreviation.to_s : - nil + tz ? tz.period_for_local(t).abbreviation.to_s : nil "(secs:#{seconds},utc~:#{ts.inspect},ltz~:#{z.inspect})" end def platform_info @@ -198,13 +180,16 @@ 'etz' => ENV['TZ'], 'tnz' => Time.now.zone, 'tzid' => defined?(TZInfo::Data), 'rv' => RUBY_VERSION, 'rp' => RUBY_PLATFORM, - 'eov' => EtOrbi::VERSION, 'rorv' => (Rails::VERSION::STRING rescue nil), 'astz' => ([ Time.zone.class, Time.zone.tzinfo.name ] rescue nil), + 'eov' => EtOrbi::VERSION, + 'eotnz' => EtOrbi::EoTime.now.zone, + 'eotnfz' => EtOrbi::EoTime.now.strftime('%z'), + 'eotlzn' => EtOrbi::EoTime.local_tzone.name, }.collect(&etos).join(',') + ',' + gather_tzs.collect(&etos).join(',') + ')' end @@ -235,11 +220,11 @@ # # keep that in the fridge for now l = Time.local(t.year, t.month, t.day, t.hour, t.min, t.sec, t.usec) - t.zone == l.zone ? local_tzone : nil + (t.zone == l.zone) ? determine_local_tzone : nil end def get_as_tzone(t) t.respond_to?(:time_zone) ? t.time_zone : nil @@ -277,11 +262,11 @@ EtOrbi.get_tzone(o) end def local_tzone - EtOrbi.local_tzone + EtOrbi.determine_local_tzone end def platform_info EtOrbi.platform_info @@ -297,11 +282,11 @@ EtOrbi.make_from_array(a, EtOrbi.get_tzone('UTC')) end def local(*a) - EtOrbi.make_from_array(a, EtOrbi.local_tzone) + EtOrbi.make_from_array(a, local_tzone) end end # # instance methods @@ -646,11 +631,11 @@ (etz && tzs.find { |z| z.name == etz }) || tzs.first end def os_tz - debian_tz || centos_tz || osx_tz + @os_tz ||= (debian_tz || centos_tz || osx_tz) end # # protected module methods @@ -702,35 +687,35 @@ tzi = TZInfo::TransitionDataTimezoneInfo.new(id) tzi.offset(id, utc_off, 0, id) tzi.create_timezone end - end def determine_local_tzones tabbs = (-6..5) .collect { |i| (Time.now + i * 30 * 24 * 3600).zone } .uniq .sort + .join('|') t = Time.now #tu = t.dup.utc # /!\ dup is necessary, #utc modifies its target twin = Time.utc(t.year, 1, 1) # winter tsum = Time.utc(t.year, 7, 1) # summer - ::TZInfo::Timezone.all.select do |tz| + @tz_all ||= ::TZInfo::Timezone.all + @tz_winter_summer ||= {} - pabbs = - [ - tz.period_for_utc(twin).abbreviation.to_s, - tz.period_for_utc(tsum).abbreviation.to_s - ].uniq.sort - - pabbs == tabbs - end + @tz_winter_summer[tabbs] ||= @tz_all + .select { |tz| + tabbs == + [ + tz.period_for_utc(twin).abbreviation.to_s, + tz.period_for_utc(tsum).abbreviation.to_s + ].uniq.sort.join('|') } end # # system tz determination