mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
#8728 Fix RubyTimestamp's '<=>' implementation to correctly compare to other types
Fixes #8730
This commit is contained in:
parent
3ebd8b9cf2
commit
bccc0d9a39
3 changed files with 15 additions and 5 deletions
|
@ -7,11 +7,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
|
||||
|
|
|
@ -211,6 +211,16 @@ public final class JrubyTimestampExtLibrary {
|
|||
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;
|
||||
}
|
||||
|
||||
private static RubyTimestamp fromRString(final Ruby runtime, final RubyString string) {
|
||||
return RubyTimestamp.newRubyTimestamp(runtime, new Timestamp(string.toString()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue