}
@Override
public long nextTime(long now)
{
QDate cal = allocateCalendar();
long time = now + 60000 - now % 60000;
cal.setGMTTime(time);
int minute = nextInterval(_minutes, cal.getMinute());
if (minute < 0) {
minute = nextInterval(_minutes, 0);
cal.setHour(cal.getHour() + 1);
}
int hour = nextInterval(_hours, cal.getHour());
if (hour < 0) {
hour = nextInterval(_hours, 0);
minute = nextInterval(_minutes, 0);
cal.setDayOfMonth(cal.getDayOfMonth() + 1);
}
int day = cal.getDayOfMonth();
if (_days != null) {
day = nextInterval(_days, cal.getDayOfMonth());
if (day < 0) {
cal.setMonth(cal.getMonth() + 1);
cal.setDayOfMonth(1);
day = nextInterval(_days, cal.getDayOfMonth());
hour = nextInterval(_hours, 0);
minute = nextInterval(_minutes, 0);
}
}
if (_daysOfWeek != null) {
int oldDayOfWeek = cal.getDayOfWeek() - 1;
int dayOfWeek = nextInterval(_daysOfWeek, oldDayOfWeek);
if (dayOfWeek >= 0) {
day += (dayOfWeek - oldDayOfWeek) % 7;
} else {
dayOfWeek = nextInterval(_daysOfWeek, 0);
day += (dayOfWeek - oldDayOfWeek + 7) % 7;
}
}
int month = cal.getMonth();
int year = (int) cal.getYear();
freeCalendar(cal);
long nextTime = nextTime(year, month, day, hour, minute);