Search in sources :

Example 1 with RecurrenceRuleIterator

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;
}
Also used : RecurrenceRuleIterator(org.dmfs.rfc5545.recur.RecurrenceRuleIterator) DateTime(org.dmfs.rfc5545.DateTime) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 DateTime (org.dmfs.rfc5545.DateTime)1 RecurrenceRuleIterator (org.dmfs.rfc5545.recur.RecurrenceRuleIterator)1