It does not seem straighforward.
I am trying this:
@Override
public int compare(Period o1, Period o2) {
return o1.toStandardDays().getDays() > o2.toStandardDays().getDays() ? -1 : (o1.toStandardDays().getDays() == o2.toStandardDays().getDays() ? 0 : 1);
}
But I get this exception:
java.lang.UnsupportedOperationException: Cannot convert to Days as this period contains months and months vary in length
at org.joda.time.Period.checkYearsAndMonths(Period.java:1455)
at org.joda.time.Period.toStandardDays(Period.java:1314)
I hoped Peroid would have an isLongerThan(Period p) method.
From the Joda Documentation:
The two
toDurationmethods areBasePeriod#toDurationTo(ReadableInstant)andBasePeriod#toDurationFrom(ReadableInstant). This means that you must choose either a start or end instant of this period in order to be able to compute its duration.If that is a problem for you, then you might want to directly use
Durationinstead ofPeriod.