나는 Joda 시간 내에 그런 유형이 있다고 믿지 않습니다. Interval
은 어쨌든 당신이 일/월 값에 관심이있는 것처럼 들리는 순간을 처리합니다.
두 개의 MonthDay
필드로 구성된 고유 한 유형을 구성해야합니다.
그런 다음 특정 값이 해당 범위 내에 있는지 확인하려면 해당 값에 대해 MonthDay
을 추가로 추가하고 세 값을 서로 비교하십시오. 예를 들어
:
// Note: this assumes you always want end to be exclusive, and start to be inclusive.
// You may well want to make end inclusive instead; it depends on your use case.
public final class MonthDayInterval {
private final MonthDay start;
private final MonthDay end;
public MonthDayInterval(MonthDay start, MonthDay end) {
this.start = start;
this.end = end;
}
public boolean contains(DateTime dateTime) {
MonthDay monthDay =
return contains(new MonthDay(
dateTime.getMonthOfYear(), dateTime.getDayOfMonth());
}
public boolean contains(MonthDay monthDay) {
boolean natural = start.compareTo(monthDay) <= 0 && monthDay.compareTo(end) < 0;
// We need to invert the result if end is after or equal to start.
return start.compareTo(end) < 0 ? natural : !natural;
}
}
흥미 롭. 내장 된 것들이 하나도 없다는 것에 놀랐습니다. 저를 올바른 방향으로 향하게 해주셔서 감사합니다. – asteri