はここでカスタム時間間隔の試みです(かなりのソリューションのようにグレーのコメント):
import org.joda.time.*;
public class TimeInterval {
private static final Instant CONSTANT = new Instant(0);
private final LocalTime from;
private final LocalTime to;
public TimeInterval(LocalTime from, LocalTime to) {
this.from = from;
this.to = to;
}
public boolean isValid() {
try { return toInterval() != null; }
catch (IllegalArgumentException e) { return false;}
}
public boolean overlapsWith(TimeInterval timeInterval) {
return this.toInterval().overlaps(timeInterval.toInterval());
}
/**
* @return this represented as a proper Interval
* @throws IllegalArgumentException if invalid (to is before from)
*/
private Interval toInterval() throws IllegalArgumentException {
return new Interval(from.toDateTime(CONSTANT), to.toDateTime(CONSTANT));
}
}
私はあなたがすでに最良の答えの男を提供したと思います。私はそれをOpenTimeRangeとして実装し、 'LocalTime'の開始と終了を指定してから、一日の営業時間を指定する配列を持っています。 – Gray