begin = getBeginDateInSpecificWeekDay(diaSemana, begin);
if (frequency == null) {
if (!begin.isAfter(end)) {
if (firstInstant) {
return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
} else {
return end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
}
}
} else {
int numberOfDaysToSum = frequency.getNumberOfDays();
while (true) {
if (begin.isAfter(end)) {
break;
}
DateTime intervalEnd = begin.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
if (!frequency.equals(FrequencyType.DAILY)
|| ((dailyFrequencyMarkSaturday || intervalEnd.getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (dailyFrequencyMarkSunday || intervalEnd
.getDayOfWeek() != SUNDAY_IN_JODA_TIME))) {
if (firstInstant) {
return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
} else {
instantResult = intervalEnd;
}
}
begin = begin.plusDays(numberOfDaysToSum);