mirror of https://github.com/apache/druid.git
JodaUtils: Bring in MIN/MAX instants a bit.
This prevents the difference overflowing a long.
This commit is contained in:
parent
b9337e883a
commit
1298b4abd3
|
@ -27,7 +27,6 @@ import com.metamx.common.guava.Comparators;
|
|||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Interval;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeSet;
|
||||
|
@ -36,9 +35,9 @@ import java.util.TreeSet;
|
|||
*/
|
||||
public class JodaUtils
|
||||
{
|
||||
// joda limits years to [-292275054,292278993] that should be reasonable
|
||||
public static final long MAX_INSTANT = new DateTime("292278993").getMillis();
|
||||
public static final long MIN_INSTANT = new DateTime("-292275054").getMillis();
|
||||
// limit intervals such that duration millis fits in a long
|
||||
public static final long MAX_INSTANT = Long.MAX_VALUE / 2;
|
||||
public static final long MIN_INSTANT = Long.MIN_VALUE / 2;
|
||||
|
||||
public static ArrayList<Interval> condenseIntervals(Iterable<Interval> intervals)
|
||||
{
|
||||
|
|
|
@ -119,4 +119,11 @@ public class JodaUtilsTest
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinMaxInterval()
|
||||
{
|
||||
final Interval interval = new Interval(JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT);
|
||||
Assert.assertEquals(Long.MAX_VALUE, interval.toDuration().getMillis());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue