Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ public static long nsecToMSec(long ns) {

@Override
public int compareTo(TimeValue timeValue) {
if (duration == -1L && timeValue.duration == -1L) {
return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also handle one being -1 and the other not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok: if one is negative and the other is non-negative then the negative one will correctly compare as less than the non-negative one already.

}
double thisValue = ((double) duration) * timeUnit.toNanos(1);
double otherValue = ((double) timeValue.duration) * timeValue.timeUnit.toNanos(1);
return Double.compare(thisValue, otherValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public void testToString() {

public void testMinusOne() {
assertThat(new TimeValue(-1).nanos(), lessThan(0L));
assertThat(TimeValue.timeValueNanos(-1), equalTo(TimeValue.MINUS_ONE));
assertThat(TimeValue.timeValueMillis(-1), equalTo(TimeValue.MINUS_ONE));
assertThat(TimeValue.timeValueSeconds(-1), equalTo(TimeValue.MINUS_ONE));
assertThat(TimeValue.timeValueMinutes(-1), equalTo(TimeValue.MINUS_ONE));
assertThat(TimeValue.timeValueHours(-1), equalTo(TimeValue.MINUS_ONE));
assertThat(TimeValue.timeValueDays(-1), equalTo(TimeValue.MINUS_ONE));
}

public void testParseTimeValue() {
Expand Down Expand Up @@ -109,6 +115,7 @@ public void testRoundTrip() {
assertThat(TimeValue.parseTimeValue(s, null, "test").getStringRep(), equalTo(s));
final TimeValue t = new TimeValue(randomIntBetween(1, 128), randomFrom(TimeUnit.values()));
assertThat(TimeValue.parseTimeValue(t.getStringRep(), null, "test"), equalTo(t));
assertThat(TimeValue.timeValueSeconds(-1), equalTo(TimeValue.parseTimeValue(TimeValue.timeValueSeconds(-1).getStringRep(), "foo")));
}

private static final String FRACTIONAL_TIME_VALUES_ARE_NOT_SUPPORTED = "fractional time values are not supported";
Expand Down