mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
#8728 Fix RubyTimestamp's '<=>' implementation to correctly compare to other types
Fixes #8730 Fixes #8733
This commit is contained in:
parent
7537412cda
commit
d0dce28b21
3 changed files with 15 additions and 5 deletions
|
@ -8,11 +8,6 @@ module LogStash
|
|||
class Timestamp
|
||||
include Comparable
|
||||
|
||||
# TODO (colin) implement in Java
|
||||
def <=>(other)
|
||||
self.time <=> other.time
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
self.== other
|
||||
end
|
||||
|
|
|
@ -36,6 +36,11 @@ describe LogStash::Timestamp do
|
|||
expect{LogStash::Timestamp.new("foobar")}.to raise_error
|
||||
end
|
||||
|
||||
it "compares to any type" do
|
||||
t = LogStash::Timestamp.new
|
||||
expect(t == '-').to be_falsey
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -254,5 +254,15 @@ public class JrubyTimestampExtLibrary implements Library {
|
|||
{
|
||||
return RubyFixnum.newFixnum(context.runtime, this.timestamp.getTime().getYear());
|
||||
}
|
||||
|
||||
@JRubyMethod(name = "<=>", required = 1)
|
||||
public IRubyObject op_cmp(final ThreadContext context, final IRubyObject other) {
|
||||
if (other instanceof JrubyTimestampExtLibrary.RubyTimestamp) {
|
||||
return ((RubyTime) ruby_time(context)).op_cmp(
|
||||
context, ((JrubyTimestampExtLibrary.RubyTimestamp) other).ruby_time(context)
|
||||
);
|
||||
}
|
||||
return context.nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue