use of org.dmfs.rfc5545.recur.RecurrenceRuleIterator in project Singularity by HubSpot.
the class RFC5545Schedule method getNextValidTime.
public Date getNextValidTime() {
final long now = System.currentTimeMillis();
DateTime startDateTime = new DateTime(dtStart.getYear(), (dtStart.getMonthOfYear() - 1), dtStart.getDayOfMonth(), dtStart.getHourOfDay(), dtStart.getMinuteOfHour(), dtStart.getSecondOfMinute());
RecurrenceRuleIterator timeIterator = recurrenceRule.iterator(startDateTime);
int count = 0;
while (timeIterator.hasNext() && (count < MAX_ITERATIONS || (recurrenceRule.hasPart(Part.COUNT) && count < recurrenceRule.getCount()))) {
count++;
long nextRunAtTimestamp = timeIterator.nextMillis();
if (nextRunAtTimestamp >= now) {
return new Date(nextRunAtTimestamp);
}
}
return null;
}
Aggregations