JodaUtils: Bring in MIN/MAX instants a bit.

This prevents the difference overflowing a long.
This commit is contained in:
Gian Merlino 2015-02-03 17:34:33 -08:00
parent b9337e883a
commit 1298b4abd3
2 changed files with 10 additions and 4 deletions

View File

@ -27,7 +27,6 @@ import com.metamx.common.guava.Comparators;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Interval; import org.joda.time.Interval;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.TreeSet; import java.util.TreeSet;
@ -36,9 +35,9 @@ import java.util.TreeSet;
*/ */
public class JodaUtils public class JodaUtils
{ {
// joda limits years to [-292275054,292278993] that should be reasonable // limit intervals such that duration millis fits in a long
public static final long MAX_INSTANT = new DateTime("292278993").getMillis(); public static final long MAX_INSTANT = Long.MAX_VALUE / 2;
public static final long MIN_INSTANT = new DateTime("-292275054").getMillis(); public static final long MIN_INSTANT = Long.MIN_VALUE / 2;
public static ArrayList<Interval> condenseIntervals(Iterable<Interval> intervals) public static ArrayList<Interval> condenseIntervals(Iterable<Interval> intervals)
{ {

View File

@ -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());
}
} }