lib/et-orbi/time.rb in et-orbi-1.2.1 vs lib/et-orbi/time.rb in et-orbi-1.2.2

- old
+ new

@@ -203,16 +203,29 @@ define_method(m) { to_time.send(m) } end def ==(o) - o.is_a?(EoTime) && - o.seconds == @seconds && - (o.zone == @zone || o.zone.current_period == @zone.current_period) + if o.is_a?(EoTime) + o.seconds == @seconds && + (o.zone == @zone || o.zone.current_period == @zone.current_period) + elsif o.is_a?(::Time) + (to_f * 1000).to_i == (o.to_f * 1000).to_i + else + false + end end - #alias eql? == # FIXME see Object#== (ri) + # Nota Bene: + # + # Unlike ==, the equal? method should never be overridden by subclasses + # as it is used to determine object identity (that is, a.equal?(b) if and + # only if a is the same object as b) + # + # The eql? method returns true if obj and other refer to the same hash key. + # This is used by Hash to test members for equality. + def >(o); @seconds > _to_f(o); end def >=(o); @seconds >= _to_f(o); end def <(o); @seconds < _to_f(o); end def <=(o); @seconds <= _to_f(o); end def <=>(o); @seconds <=> _to_f(o); end @@ -412,10 +425,10 @@ def _to_f(o) fail ArgumentError( "Comparison of EoTime with #{o.inspect} failed" - ) unless o.is_a?(EoTime) || o.is_a?(Time) + ) unless o.respond_to?(:to_f) o.to_f end end end