skip = true;
}
}
case HOUR: {
if(skip) {
LocalTime lt = tradingSession.start();
dt = dt.withHourOfDay(lt.getHourOfDay());
}else{
dt = dt.plusHours(interval);
tradingSession = getTradingSessionOnOrAfter(dt);
if(!tradingSession.contains(dt)) {
if(tradingSession.day() < dt.getDayOfWeek()) {
dt = dt.plusDays((DateTimeConstants.SUNDAY - dt.getDayOfWeek()) + 1);
}
dt = dt.withDayOfWeek(tradingSession.day());
dt = dt.withHourOfDay(tradingSession.start().getHourOfDay());
}
skip = true;
}
}
case MINUTE: {
if(skip) {
LocalTime lt = tradingSession.start();
dt = dt.withMinuteOfHour(lt.getMinuteOfHour());
}else{
dt = dt.plusMinutes(interval);
tradingSession = getTradingSessionOnOrAfter(dt);
if(!tradingSession.contains(dt)) {
if(tradingSession.day() < dt.getDayOfWeek()) {
dt = dt.plusDays((DateTimeConstants.SUNDAY - dt.getDayOfWeek()) + 1);
}
dt = dt.withDayOfWeek(tradingSession.day());
LocalTime lt = tradingSession.start();
dt = dt.withHourOfDay(lt.getHourOfDay()).withMinuteOfHour(lt.getMinuteOfHour());
}
skip = true;
}
}
case SECOND: {
if(skip) {
dt = dt.withSecondOfMinute(0);
}else{
dt = dt.plusSeconds(interval);
tradingSession = getTradingSessionOnOrAfter(dt);
if(!tradingSession.contains(dt)) {
if(tradingSession.day() < dt.getDayOfWeek()) {
dt = dt.plusDays((DateTimeConstants.SUNDAY - dt.getDayOfWeek()) + 1);
}
dt = dt.withDayOfWeek(tradingSession.day());
LocalTime lt = tradingSession.start();
dt = dt.withHourOfDay(lt.getHourOfDay()).withMinuteOfHour(lt.getMinuteOfHour());
dt = dt.withSecondOfMinute(0);
}
}
break;
}
case TICK: {
tradingSession = getTradingSessionOnOrAfter(dt);
if(!tradingSession.contains(dt)) {
if(tradingSession.day() < dt.getDayOfWeek()) {
dt = dt.plusDays((DateTimeConstants.SUNDAY - dt.getDayOfWeek()) + 1);
}
dt = dt.withDayOfWeek(tradingSession.day());
LocalTime lt = tradingSession.start();
dt = dt.withHourOfDay(lt.getHourOfDay()).withMinuteOfHour(lt.getMinuteOfHour());
dt = dt.withSecondOfMinute(lt.getSecondOfMinute()).withMillisOfSecond(0);
}
}
// Guarantee new date is aligned to a business date.
calculator.setStartDate(dt.toLocalDate());
LocalDate ldt = calculator.getCurrentBusinessDate();
if(!ldt.isEqual(dt.toLocalDate())) {
tradingSession = getTradingSessionOnOrAfter(ldt.toDateTime(dt.toLocalTime()));
if(tradingSession.day() < dt.getDayOfWeek()) {
dt = dt.plusDays((DateTimeConstants.SUNDAY - dt.getDayOfWeek()) + 1);
}
dt = dt.withDayOfWeek(tradingSession.day());
LocalTime lt = tradingSession.start();
dt = dt.withHourOfDay(lt.getHourOfDay()).withMinuteOfHour(lt.getMinuteOfHour()).withSecondOfMinute(0);
}
}
return dt;
}