lib/et-orbi.rb in et-orbi-1.0.6 vs lib/et-orbi.rb in et-orbi-1.0.7

- old
+ new

@@ -5,11 +5,11 @@ require 'tzinfo' module EtOrbi - VERSION = '1.0.6' + VERSION = '1.0.7' # # module methods class << self @@ -28,11 +28,11 @@ #rold = RUBY_VERSION < '1.9.0' #rold = RUBY_VERSION < '2.0.0' begin DateTime.parse(str) rescue - fail ArgumentError, "no time information in #{str.inspect}" + fail ArgumentError, "No time information in #{str.inspect}" end #if rold # # is necessary since Time.parse('xxx') in Ruby < 1.9 yields `now` str_zone = get_tzone(list_iso8601_zones(str).last) @@ -85,18 +85,19 @@ when Array then make_from_array(o, zone) when String then make_from_string(o, zone) when Numeric then make_from_numeric(o, zone) when ::EtOrbi::EoTime then make_from_eotime(o, zone) else fail ArgumentError.new( - "cannot turn #{o.inspect} to a ::EtOrbi::EoTime instance") + "Cannot turn #{o.inspect} to a ::EtOrbi::EoTime instance") end end def make_from_time(t, zone) z = zone || + get_as_tzone(t) || get_tzone(t.zone) || get_local_tzone(t) z ||= t.zone # pass the abbreviation anyway, @@ -216,25 +217,32 @@ protected def get_local_tzone(t) -# lt = local_tzone -# lp = lt.period_for_local(t) -# ab = lp.abbreviation.to_s -# -# return lt \ -# if ab == t.zone -# return lt \ -# if ab.match(/\A[-+]\d{2}(:?\d{2})?\z/) && lp.utc_offset == t.utc_offset -# -# nil + #lt = local_tzone + #lp = lt.period_for_local(t) + #ab = lp.abbreviation.to_s + # + #return lt \ + # if ab == t.zone + #return lt \ + # if ab.match(/\A[-+]\d{2}(:?\d{2})?\z/) && lp.utc_offset == t.utc_offset + # + #nil + # + # 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 end + + def get_as_tzone(t) + + t.respond_to?(:time_zone) ? t.time_zone : nil + end end # Our EoTime class (which quacks like a ::Time). # # An EoTime instance should respond to most of the methods ::Time instances @@ -292,11 +300,11 @@ @seconds = s.to_f @zone = self.class.get_tzone(zone || :local) fail ArgumentError.new( - "cannot determine timezone from #{zone.inspect}" + + "Cannot determine timezone from #{zone.inspect}" + "\n#{EtOrbi.render_nozone_time(s)}" + "\n#{EtOrbi.platform_info.sub(',debian:', ",\ndebian:")}" + "\nTry setting `ENV['TZ'] = 'Continent/City'` in your script " + "(see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)" + (defined?(TZInfo::Data) ? '' : "\nand adding gem 'tzinfo-data'") @@ -477,15 +485,15 @@ nt = self.dup nt.seconds += dir * t.to_f nt when ::Time, ::EtOrbi::EoTime fail ArgumentError.new( - "cannot add #{t.class} to EoTime") if dir > 0 + "Cannot add #{t.class} to EoTime") if dir > 0 @seconds + dir * t.to_f else fail ArgumentError.new( - "cannot call add or subtract #{t.class} to EoTime instance") + "Cannot call add or subtract #{t.class} to EoTime instance") end end def localtime(zone=nil) @@ -548,10 +556,10 @@ end def _to_f(o) fail ArgumentError( - "comparison of EoTime with #{o.inspect} failed" + "Comparison of EoTime with #{o.inspect} failed" ) unless o.is_a?(EoTime) || o.is_a?(Time) o.to_f end end