Commit cfca417d authored by R.W.Majeed's avatar R.W.Majeed

ordering by accurate first, if min instants are equal

parent a2b66e83
......@@ -386,7 +386,12 @@ public class DateTimeAccuracy implements Comparable<DateTimeAccuracy> {
}
@Override
public int compareTo(DateTimeAccuracy o) {
return instant.compareTo(o.instant);
int cmp = instant.compareTo(o.instant);
// if instants are equal, order by accuracy. more accurate comes first
if( cmp == 0 ){
cmp = accuracy.compareTo(o.accuracy);
}
return cmp;
}
@Override
......
......@@ -164,5 +164,19 @@ public class TestDateTimeAccuracy {
// date should be treated as if it had a +08:00 offset
assertEquals("2001-02-02T20Z", a.toPartialIso8601(ZoneId.of("UTC")));
}
@Test
public void verifyComparison() throws ParseException{
ZoneId zone = ZoneOffset.UTC.normalized();
DateTimeAccuracy a = DateTimeAccuracy.parsePartialIso8601("2001-02-03T04", zone);
DateTimeAccuracy b = DateTimeAccuracy.parsePartialIso8601("2001-02-03T04:00", zone);
// instant min are equal
Assert.assertEquals(a.toInstantMin(), b.toInstantMin());
// yet a and b are not equal
Assert.assertNotEquals(a, b);
// defined order
Assert.assertTrue(a.compareTo(b) > 0);
Assert.assertTrue(b.compareTo(a) < 0);
}
// TODO: further tests
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment