protected MutableInterval _nextMutableInterval(PointerType pointer) {
int halfDay = RepeaterDay.DAY_SECONDS / 2;
int fullDay = RepeaterDay.DAY_SECONDS;
DateTime now = getNow();
Tick tick = getType();
boolean first = false;
if (_currentTime == null) {
first = true;
DateTime midnight = Time.ymd(now);
DateTime yesterdayMidnight = midnight.minusSeconds(fullDay);
DateTime tomorrowMidnight = midnight.plusSeconds(fullDay);
boolean done = false;
if (pointer == Pointer.PointerType.FUTURE) {
if (tick.isAmbiguous()) {
List<DateTime> futureDates = new LinkedList<DateTime>();
futureDates.add( midnight.plusSeconds(tick.intValue()));
futureDates.add(midnight.plusSeconds( halfDay + tick.intValue()));
futureDates.add(tomorrowMidnight.plusSeconds(tick.intValue()));
for (DateTime futureDate : futureDates) {
if (futureDate.getMillis() > now.getMillis() || futureDate.equals(now)) {
_currentTime = futureDate;
done = true;
break;
}
}
}
else {
List<DateTime> futureDates = new LinkedList<DateTime>();
futureDates.add(midnight.plusSeconds(tick.intValue()));
futureDates.add(tomorrowMidnight.plusSeconds(tick.intValue()));
for (DateTime futureDate : futureDates) {
if (futureDate.getMillis() > now.getMillis() || futureDate.equals(now)) {
_currentTime = futureDate;
done = true;
break;
}
}
}
}
else {
if (tick.isAmbiguous()) {
List<DateTime> pastDates = new LinkedList<DateTime>();
pastDates.add(midnight.plusSeconds(halfDay + tick.intValue()));
pastDates.add(midnight.plusSeconds(tick.intValue()));
pastDates.add(yesterdayMidnight.plusSeconds(tick.intValue() * 2));
for (DateTime pastDate : pastDates) {
if (pastDate.getMillis() > now.getMillis() || pastDate.equals(now)) {
_currentTime = pastDate;
done = true;
break;
}
}
}
else {
List<DateTime> pastDates = new LinkedList<DateTime>();
pastDates.add(midnight.plusSeconds( tick.intValue()));
pastDates.add(yesterdayMidnight.plusSeconds( tick.intValue()));
for (DateTime pastDate : pastDates) {
if (pastDate.getMillis() > now.getMillis() || pastDate.equals(now)) {
_currentTime = pastDate;
done = true;
break;
}
}
}
}
if (!done && _currentTime == null) {
throw new IllegalStateException("Current time cannot be null at this point.");
}
}
if (!first) {
int increment = (tick.isAmbiguous()) ? halfDay : fullDay;
int direction = (pointer == Pointer.PointerType.FUTURE) ? 1 : -1;
_currentTime = _currentTime.plusSeconds( direction * increment);
}
return new MutableInterval(_currentTime, _currentTime.plusSeconds(getWidth()));