Determines if the entry describes a recurring event.

@return true if the entry is recurring
@see #recurrenceRuleProperty()
192625
public final boolean isRecurring() {
        return recurrenceRule != null && !(recurrenceRule.get() == null) && !recurrenceRule.get().trim().equals(""); //$NON-NLS-1$
    }
1077632
public boolean isDeathRelatedEvent(final Attribute event) {
        if (isDeathEvent(event)) {
            return true;
        }
        if (isPostDeathEvent(event)) {
            return true;
        }
        return isUnorderedEvent(event);
    }
556960
public boolean matchRemoteEvent(final TenantAwareEvent tenantAwareEvent) {
        if (!(tenantAwareEvent instanceof RemoteIdEvent) || entityClass == null || entityIds == null) {
            return false;
        }
        final RemoteIdEvent remoteIdEvent = (RemoteIdEvent) tenantAwareEvent;
        try {
            final Class<?> remoteEntityClass = Class.forName(remoteIdEvent.getEntityClass());
            return entityClass.isAssignableFrom(remoteEntityClass) && entityIds.contains(remoteIdEvent.getEntityId());
        } catch (final ClassNotFoundException e) {
            LOG.error("Entity Class of remoteIdEvent cannot be found", e);
            return false;
        }

    }
638942
protected function processRecurrences()
    {
        $events = (isset($this->cal['VEVENT'])) ? $this->cal['VEVENT'] : array();

        $recurrenceEvents    = array();
        $allRecurrenceEvents = array();

        if (!empty($events)) {
            foreach ($events as $anEvent) {
                if (isset($anEvent['RRULE']) && $anEvent['RRULE'] !== '') {
                    // Tag as generated by a recurrence rule
                    $anEvent['RRULE_array'][2] = self::RECURRENCE_EVENT;

                    $countNb = 0;

                    $initialStart             = new \DateTime($anEvent['DTSTART_array'][1]);
                    $initialStartTimeZoneName = $initialStart->getTimezone()->getName();

                    if (isset($anEvent['DTEND'])) {
                        $initialEnd             = new \DateTime($anEvent['DTEND_array'][1]);
                        $initialEndTimeZoneName = $initialEnd->getTimezone()->getName();
                    } else {
                        $initialEndTimeZoneName = $initialStartTimeZoneName;
                    }

                    // Recurring event, parse RRULE and add appropriate duplicate events
                    $rrules = array();
                    $rruleStrings = explode(';', $anEvent['RRULE']);

                    foreach ($rruleStrings as $s) {
                        list($k, $v) = explode('=', $s);
                        $rrules[$k] = $v;
                    }

                    // Get frequency
                    $frequency = $rrules['FREQ'];
                    // Get Start timestamp
                    $startTimestamp = $initialStart->getTimestamp();

                    if (isset($anEvent['DTEND'])) {
                        $endTimestamp = $initialEnd->getTimestamp();
                    } elseif (isset($anEvent['DURATION'])) {
                        $duration = end($anEvent['DURATION_array']);
                        $endTimestamp = $this->parseDuration($anEvent['DTSTART'], $duration);
                    } else {
                        $endTimestamp = $anEvent['DTSTART_array'][2];
                    }

                    $eventTimestampOffset = $endTimestamp - $startTimestamp;
                    // Get Interval
                    $interval = (isset($rrules['INTERVAL']) && $rrules['INTERVAL'] !== '') ? $rrules['INTERVAL'] : 1;

                    $dayNumber = null;
                    $weekday   = null;

                    if (in_array($frequency, array('MONTHLY', 'YEARLY')) && isset($rrules['BYDAY']) && $rrules['BYDAY'] !== '') {
                        // Deal with BYDAY
                        $byDay     = $rrules['BYDAY'];
                        $dayNumber = intval($byDay);

                        if (empty($dayNumber)) { // Returns 0 when no number defined in BYDAY
                            if (!isset($rrules['BYSETPOS'])) {
                                $dayNumber = 1; // Set first as default
                            } elseif (is_numeric($rrules['BYSETPOS'])) {
                                $dayNumber = $rrules['BYSETPOS'];
                            }
                        }

                        $weekday = substr($byDay, -2);
                    }

                    if (is_int($this->defaultSpan)) {
                        $untilDefault = date_create('now');
                        $untilDefault->modify($this->defaultSpan . ' year');
                        $untilDefault->setTime(23, 59, 59); // End of the day
                    } else {
                        trigger_error('ICal::defaultSpan: User defined value is not an integer', E_USER_NOTICE);
                    }

                    // Compute EXDATEs
                    $exdates = $this->parseExdates($anEvent);

                    $countOrig = null;

                    if (isset($rrules['UNTIL'])) {
                        // Get Until
                        $until = strtotime($rrules['UNTIL']);
                    } elseif (isset($rrules['COUNT'])) {
                        $countOrig = (is_numeric($rrules['COUNT']) && $rrules['COUNT'] > 1) ? $rrules['COUNT'] : 0;

                        // Increment count by the number of excluded dates
                        $countOrig += sizeof($exdates);

                        // Remove one to exclude the occurrence that initialises the rule
                        $count = ($countOrig - 1);

                        if ($interval >= 2) {
                            $count += ($count > 0) ? ($count * $interval) : 0;
                        }

                        $countNb = 1;
                        $offset  = "+{$count} " . $this->frequencyConversion[$frequency];
                        $until   = strtotime($offset, $startTimestamp);

                        if (in_array($frequency, array('MONTHLY', 'YEARLY'))
                            && isset($rrules['BYDAY']) && $rrules['BYDAY'] !== ''
                        ) {
                            $dtstart = date_create($anEvent['DTSTART']);

                            if (!$dtstart) {
                                continue;
                            }

                            for ($i = 1; $i <= $count; $i++) {
                                $dtstartClone = clone $dtstart;
                                $dtstartClone->modify('next ' . $this->frequencyConversion[$frequency]);
                                $offset = "{$this->convertDayOrdinalToPositive($dayNumber, $weekday, $dtstartClone)} {$this->weekdays[$weekday]} of " . $dtstartClone->format('F Y H:i:01');
                                $dtstart->modify($offset);
                            }

                            // Jumping X months forwards doesn't mean
                            // the end date will fall on the same day defined in BYDAY
                            // Use the largest of these to ensure we are going far enough
                            // in the future to capture our final end day
                            $until = max($until, $dtstart->format(self::UNIX_FORMAT));
                        }

                        unset($offset);
                    } elseif (isset($untilDefault)) {
                        $until = $untilDefault->getTimestamp();
                    }

                    $until = intval($until);

                    // Decide how often to add events and do so
                    switch ($frequency) {
                        case 'DAILY':
                            // Simply add a new event each interval of days until UNTIL is reached
                            $offset = "+{$interval} day";
                            $recurringTimestamp = strtotime($offset, $startTimestamp);

                            while ($recurringTimestamp <= $until) {
                                $dayRecurringTimestamp = $recurringTimestamp;

                                // Adjust time zone from initial event
                                $dayRecurringOffset = 0;
                                if ($this->useTimeZoneWithRRules) {
                                    $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $dayRecurringTimestamp);
                                    $recurringTimeZone->setTimezone($initialStart->getTimezone());
                                    $dayRecurringOffset = $recurringTimeZone->getOffset();
                                    $dayRecurringTimestamp += $dayRecurringOffset;
                                }

                                // Add event
                                $anEvent['DTSTART'] = date(self::DATE_TIME_FORMAT, $dayRecurringTimestamp) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '');
                                $anEvent['DTSTART_array'][1] = $anEvent['DTSTART'];
                                $anEvent['DTSTART_array'][2] = $dayRecurringTimestamp;
                                $anEvent['DTEND_array']      = $anEvent['DTSTART_array'];
                                $anEvent['DTEND_array'][2]  += $eventTimestampOffset;
                                $anEvent['DTEND'] = date(
                                    self::DATE_TIME_FORMAT,
                                    $anEvent['DTEND_array'][2]
                                ) . (($initialEndTimeZoneName === 'Z') ? 'Z' : '');
                                $anEvent['DTEND_array'][1] = $anEvent['DTEND'];

                                // Exclusions
                                $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $dayRecurringOffset) {
                                    return self::isExdateMatch($exdate, $anEvent, $dayRecurringOffset);
                                });

                                if (isset($anEvent['UID'])) {
                                    $searchDate = $anEvent['DTSTART'];
                                    if (isset($anEvent['DTSTART_array'][0]['TZID'])) {
                                        $searchDate = sprintf(self::ICAL_DATE_TIME_TEMPLATE, $anEvent['DTSTART_array'][0]['TZID']) . $searchDate;
                                    }

                                    if (isset($this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                        $searchDateUtc = $this->iCalDateToUnixTimestamp($searchDate, true, true);
                                        if (in_array($searchDateUtc, $this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                            $isExcluded = true;
                                        }
                                    }
                                }

                                if (!$isExcluded) {
                                    $anEvent            = $this->processEventIcalDateTime($anEvent);
                                    $recurrenceEvents[] = $anEvent;
                                    $this->eventCount++;

                                    // If RRULE[COUNT] is reached then break
                                    if (isset($rrules['COUNT'])) {
                                        $countNb++;

                                        if ($countNb >= $countOrig) {
                                            break;
                                        }
                                    }
                                }

                                // Move forwards
                                $recurringTimestamp = strtotime($offset, $recurringTimestamp);
                            }

                            $recurrenceEvents    = $this->trimToRecurrenceCount($rrules, $recurrenceEvents);
                            $allRecurrenceEvents = array_merge($allRecurrenceEvents, $recurrenceEvents);
                            $recurrenceEvents    = array(); // Reset
                            break;

                        case 'WEEKLY':
                            // Create offset
                            $offset = "+{$interval} week";

                            $wkst  = (isset($rrules['WKST']) && in_array($rrules['WKST'], array('SA', 'SU', 'MO'))) ? $rrules['WKST'] : $this->defaultWeekStart;
                            $aWeek = $this->weeks[$wkst];
                            $days  = array('SA' => 'Saturday', 'SU' => 'Sunday', 'MO' => 'Monday');

                            // Build list of days of week to add events
                            $weekdays = $aWeek;

                            if (isset($rrules['BYDAY']) && $rrules['BYDAY'] !== '') {
                                $byDays = explode(',', $rrules['BYDAY']);
                            } else {
                                // A textual representation of a day, two letters (e.g. SU)
                                $byDays = array(mb_substr(strtoupper($initialStart->format('D')), 0, 2));
                            }

                            // Get timestamp of first day of start week
                            $weekRecurringTimestamp = (strcasecmp($initialStart->format('l'), $this->weekdays[$wkst]) === 0)
                                ? $startTimestamp
                                : strtotime("last {$days[$wkst]} " . $initialStart->format('H:i:s'), $startTimestamp);

                            // Step through weeks
                            while ($weekRecurringTimestamp <= $until) {
                                $dayRecurringTimestamp = $weekRecurringTimestamp;

                                // Adjust time zone from initial event
                                $dayRecurringOffset = 0;
                                if ($this->useTimeZoneWithRRules) {
                                    $dayRecurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $dayRecurringTimestamp);
                                    $dayRecurringTimeZone->setTimezone($initialStart->getTimezone());
                                    $dayRecurringOffset = $dayRecurringTimeZone->getOffset();
                                    $dayRecurringTimestamp += $dayRecurringOffset;
                                }

                                foreach ($weekdays as $day) {
                                    // Check if day should be added
                                    if (in_array($day, $byDays) && $dayRecurringTimestamp > $startTimestamp
                                        && $dayRecurringTimestamp <= $until
                                    ) {
                                        // Add event
                                        $anEvent['DTSTART'] = date(self::DATE_TIME_FORMAT, $dayRecurringTimestamp) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '');
                                        $anEvent['DTSTART_array'][1] = $anEvent['DTSTART'];
                                        $anEvent['DTSTART_array'][2] = $dayRecurringTimestamp;
                                        $anEvent['DTEND_array']      = $anEvent['DTSTART_array'];
                                        $anEvent['DTEND_array'][2]  += $eventTimestampOffset;
                                        $anEvent['DTEND'] = date(
                                            self::DATE_TIME_FORMAT,
                                            $anEvent['DTEND_array'][2]
                                        ) . (($initialEndTimeZoneName === 'Z') ? 'Z' : '');
                                        $anEvent['DTEND_array'][1] = $anEvent['DTEND'];

                                        // Exclusions
                                        $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $dayRecurringOffset) {
                                            return self::isExdateMatch($exdate, $anEvent, $dayRecurringOffset);
                                        });

                                        if (isset($anEvent['UID'])) {
                                            $searchDate = $anEvent['DTSTART'];
                                            if (isset($anEvent['DTSTART_array'][0]['TZID'])) {
                                                $searchDate = sprintf(self::ICAL_DATE_TIME_TEMPLATE, $anEvent['DTSTART_array'][0]['TZID']) . $searchDate;
                                            }

                                            if (isset($this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                $searchDateUtc = $this->iCalDateToUnixTimestamp($searchDate, true, true);
                                                if (in_array($searchDateUtc, $this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                    $isExcluded = true;
                                                }
                                            }
                                        }

                                        if (!$isExcluded) {
                                            $anEvent            = $this->processEventIcalDateTime($anEvent);
                                            $recurrenceEvents[] = $anEvent;
                                            $this->eventCount++;

                                            // If RRULE[COUNT] is reached then break
                                            if (isset($rrules['COUNT'])) {
                                                $countNb++;

                                                if ($countNb >= $countOrig) {
                                                    break 2;
                                                }
                                            }
                                        }
                                    }

                                    // Move forwards a day
                                    $dayRecurringTimestamp = strtotime('+1 day', $dayRecurringTimestamp);
                                }

                                // Move forwards $interval weeks
                                $weekRecurringTimestamp = strtotime($offset, $weekRecurringTimestamp);
                            }

                            $recurrenceEvents    = $this->trimToRecurrenceCount($rrules, $recurrenceEvents);
                            $allRecurrenceEvents = array_merge($allRecurrenceEvents, $recurrenceEvents);
                            $recurrenceEvents    = array(); // Reset
                            break;

                        case 'MONTHLY':
                            // Create offset
                            $recurringTimestamp = $startTimestamp;
                            $offset = "+{$interval} month";

                            if (isset($rrules['BYMONTHDAY']) && $rrules['BYMONTHDAY'] !== '') {
                                // Deal with BYMONTHDAY
                                $monthdays = explode(',', $rrules['BYMONTHDAY']);

                                while ($recurringTimestamp <= $until) {
                                    foreach ($monthdays as $key => $monthday) {
                                        $monthRecurringTimestamp = null;

                                        if ($key === 0) {
                                            // Ensure original event conforms to monthday rule
                                            $anEvent['DTSTART'] = gmdate(
                                                'Ym' . sprintf('%02d', $monthday) . '\T' . self::TIME_FORMAT,
                                                strtotime($anEvent['DTSTART'])
                                            ) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '');

                                            $anEvent['DTEND'] = gmdate(
                                                'Ym' . sprintf('%02d', $monthday) . '\T' . self::TIME_FORMAT,
                                                isset($anEvent['DURATION'])
                                                        ? $this->parseDuration($anEvent['DTSTART'], end($anEvent['DURATION_array']))
                                                        : strtotime($anEvent['DTEND'])
                                            ) . (($initialEndTimeZoneName === 'Z') ? 'Z' : '');

                                            $anEvent['DTSTART_array'][1] = $anEvent['DTSTART'];
                                            $anEvent['DTSTART_array'][2] = $this->iCalDateToUnixTimestamp($anEvent['DTSTART']);
                                            $anEvent['DTEND_array'][1]   = $anEvent['DTEND'];
                                            $anEvent['DTEND_array'][2]   = $this->iCalDateToUnixTimestamp($anEvent['DTEND']);

                                            // Ensure recurring timestamp confirms to BYMONTHDAY rule
                                            $monthRecurringTimestamp = $this->iCalDateToUnixTimestamp(
                                                gmdate(
                                                    'Ym' . sprintf('%02d', $monthday) . '\T' . self::TIME_FORMAT,
                                                    $recurringTimestamp
                                                ) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '')
                                            );
                                        }

                                        // Adjust time zone from initial event
                                        $monthRecurringOffset = 0;
                                        if ($this->useTimeZoneWithRRules) {
                                            $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $monthRecurringTimestamp);
                                            $recurringTimeZone->setTimezone($initialStart->getTimezone());
                                            $monthRecurringOffset = $recurringTimeZone->getOffset();
                                            $monthRecurringTimestamp += $monthRecurringOffset;
                                        }

                                        if (($monthRecurringTimestamp > $startTimestamp) && ($monthRecurringTimestamp <= $until)) {
                                            // Add event
                                            $anEvent['DTSTART'] = date(
                                                'Ym' . sprintf('%02d', $monthday) . '\T' . self::TIME_FORMAT,
                                                $monthRecurringTimestamp
                                            ) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '');
                                            $anEvent['DTSTART_array'][1] = $anEvent['DTSTART'];
                                            $anEvent['DTSTART_array'][2] = $monthRecurringTimestamp;
                                            $anEvent['DTEND_array']      = $anEvent['DTSTART_array'];
                                            $anEvent['DTEND_array'][2]  += $eventTimestampOffset;
                                            $anEvent['DTEND'] = date(
                                                self::DATE_TIME_FORMAT,
                                                $anEvent['DTEND_array'][2]
                                            ) . (($initialEndTimeZoneName === 'Z') ? 'Z' : '');
                                            $anEvent['DTEND_array'][1] = $anEvent['DTEND'];

                                            // Exclusions
                                            $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $monthRecurringOffset) {
                                                return self::isExdateMatch($exdate, $anEvent, $monthRecurringOffset);
                                            });

                                            if (isset($anEvent['UID'])) {
                                                $searchDate = $anEvent['DTSTART'];
                                                if (isset($anEvent['DTSTART_array'][0]['TZID'])) {
                                                    $searchDate = sprintf(self::ICAL_DATE_TIME_TEMPLATE, $anEvent['DTSTART_array'][0]['TZID']) . $searchDate;
                                                }

                                                if (isset($this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                    $searchDateUtc = $this->iCalDateToUnixTimestamp($searchDate, true, true);
                                                    if (in_array($searchDateUtc, $this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                        $isExcluded = true;
                                                    }
                                                }
                                            }

                                            if (!$isExcluded) {
                                                $anEvent = $this->processEventIcalDateTime($anEvent);
                                                $recurrenceEvents[] = $anEvent;
                                                $this->eventCount++;

                                                // If RRULE[COUNT] is reached then break
                                                if (isset($rrules['COUNT'])) {
                                                    $countNb++;

                                                    if ($countNb >= $countOrig) {
                                                        break 2;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Move forwards
                                    $recurringTimestamp = strtotime($offset, $recurringTimestamp);
                                }
                            } elseif (isset($rrules['BYDAY']) && $rrules['BYDAY'] !== '') {
                                while ($recurringTimestamp <= $until) {
                                    $monthRecurringTimestamp = $recurringTimestamp;

                                    // Adjust time zone from initial event
                                    $monthRecurringOffset = 0;

                                    if ($this->useTimeZoneWithRRules) {
                                        $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $monthRecurringTimestamp);
                                        $recurringTimeZone->setTimezone($initialStart->getTimezone());
                                        $monthRecurringOffset = $recurringTimeZone->getOffset();
                                        $monthRecurringTimestamp += $monthRecurringOffset;
                                    }

                                    $eventStartDesc = "{$this->convertDayOrdinalToPositive($dayNumber, $weekday, $monthRecurringTimestamp)} {$this->weekdays[$weekday]} of "
                                        . date(self::DATE_TIME_FORMAT_PRETTY, $monthRecurringTimestamp);
                                    $eventStartTimestamp = strtotime($eventStartDesc);

                                    if (intval($rrules['BYDAY']) === 0) {
                                        $lastDayDesc = "last {$this->weekdays[$weekday]} of "
                                            . date(self::DATE_TIME_FORMAT_PRETTY, $monthRecurringTimestamp);
                                    } else {
                                        $lastDayDesc = "{$this->convertDayOrdinalToPositive($dayNumber, $weekday, $monthRecurringTimestamp)} {$this->weekdays[$weekday]} of "
                                            . date(self::DATE_TIME_FORMAT_PRETTY, $monthRecurringTimestamp);
                                    }

                                    $lastDayTimestamp = strtotime($lastDayDesc);

                                    do {
                                        // Prevent 5th day of a month from showing up on the next month
                                        // If BYDAY and the event falls outside the current month, skip the event

                                        $compareCurrentMonth = date('F', $monthRecurringTimestamp);
                                        $compareEventMonth   = date('F', $eventStartTimestamp);

                                        if ($compareCurrentMonth !== $compareEventMonth) {
                                            $monthRecurringTimestamp = strtotime($offset, $monthRecurringTimestamp);
                                            continue;
                                        }

                                        if ($eventStartTimestamp > $startTimestamp && $eventStartTimestamp <= $until) {
                                            $anEvent['DTSTART'] = date(self::DATE_TIME_FORMAT, $eventStartTimestamp) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '');
                                            $anEvent['DTSTART_array'][1] = $anEvent['DTSTART'];
                                            $anEvent['DTSTART_array'][2] = $eventStartTimestamp;
                                            $anEvent['DTEND_array']      = $anEvent['DTSTART_array'];
                                            $anEvent['DTEND_array'][2]  += $eventTimestampOffset;
                                            $anEvent['DTEND'] = date(
                                                self::DATE_TIME_FORMAT,
                                                $anEvent['DTEND_array'][2]
                                            ) . (($initialEndTimeZoneName === 'Z') ? 'Z' : '');
                                            $anEvent['DTEND_array'][1] = $anEvent['DTEND'];

                                            // Exclusions
                                            $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $monthRecurringOffset) {
                                                return self::isExdateMatch($exdate, $anEvent, $monthRecurringOffset);
                                            });

                                            if (isset($anEvent['UID'])) {
                                                $searchDate = $anEvent['DTSTART'];
                                                if (isset($anEvent['DTSTART_array'][0]['TZID'])) {
                                                    $searchDate = sprintf(self::ICAL_DATE_TIME_TEMPLATE, $anEvent['DTSTART_array'][0]['TZID']) . $searchDate;
                                                }

                                                if (isset($this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                    $searchDateUtc = $this->iCalDateToUnixTimestamp($searchDate, true, true);
                                                    if (in_array($searchDateUtc, $this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                        $isExcluded = true;
                                                    }
                                                }
                                            }

                                            if (!$isExcluded) {
                                                $anEvent            = $this->processEventIcalDateTime($anEvent);
                                                $recurrenceEvents[] = $anEvent;
                                                $this->eventCount++;

                                                // If RRULE[COUNT] is reached then break
                                                if (isset($rrules['COUNT'])) {
                                                    $countNb++;

                                                    if ($countNb >= $countOrig) {
                                                        break 2;
                                                    }
                                                }
                                            }
                                        }

                                        if (isset($rrules['BYSETPOS'])) {
                                            // BYSETPOS is defined so skip
                                            // looping through each week
                                            $lastDayTimestamp = $eventStartTimestamp;
                                        }

                                        $eventStartTimestamp += self::SECONDS_IN_A_WEEK;
                                    } while ($eventStartTimestamp <= $lastDayTimestamp);

                                    // Move forwards
                                    $recurringTimestamp = strtotime($offset, $recurringTimestamp);
                                }
                            }

                            $recurrenceEvents    = $this->trimToRecurrenceCount($rrules, $recurrenceEvents);
                            $allRecurrenceEvents = array_merge($allRecurrenceEvents, $recurrenceEvents);
                            $recurrenceEvents    = array(); // Reset
                            break;

                        case 'YEARLY':
                            // Create offset
                            $recurringTimestamp = $startTimestamp;
                            $offset = "+{$interval} year";

                            // Deal with BYMONTH
                            if (isset($rrules['BYMONTH']) && $rrules['BYMONTH'] !== '') {
                                $bymonths = explode(',', $rrules['BYMONTH']);
                            } else {
                                $bymonths = array();
                            }

                            // Check if BYDAY rule exists
                            if (isset($rrules['BYDAY']) && $rrules['BYDAY'] !== '') {
                                while ($recurringTimestamp <= $until) {
                                    $yearRecurringTimestamp = $recurringTimestamp;

                                    // Adjust time zone from initial event
                                    $yearRecurringOffset = 0;

                                    if ($this->useTimeZoneWithRRules) {
                                        $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $yearRecurringTimestamp);
                                        $recurringTimeZone->setTimezone($initialStart->getTimezone());
                                        $yearRecurringOffset = $recurringTimeZone->getOffset();
                                        $yearRecurringTimestamp += $yearRecurringOffset;
                                    }

                                    foreach ($bymonths as $bymonth) {
                                        $eventStartDesc = "{$this->convertDayOrdinalToPositive($dayNumber, $weekday, $yearRecurringTimestamp)} {$this->weekdays[$weekday]}"
                                            . " of {$this->monthNames[$bymonth]} "
                                            . gmdate('Y H:i:s', $yearRecurringTimestamp);
                                        $eventStartTimestamp = strtotime($eventStartDesc);

                                        if (intval($rrules['BYDAY']) === 0) {
                                            $lastDayDesc = "last {$this->weekdays[$weekday]}"
                                                . " of {$this->monthNames[$bymonth]} "
                                                . gmdate('Y H:i:s', $yearRecurringTimestamp);
                                        } else {
                                            $lastDayDesc = "{$this->convertDayOrdinalToPositive($dayNumber, $weekday, $yearRecurringTimestamp)} {$this->weekdays[$weekday]}"
                                                . " of {$this->monthNames[$bymonth]} "
                                                . gmdate('Y H:i:s', $yearRecurringTimestamp);
                                        }

                                        $lastDayTimestamp = strtotime($lastDayDesc);

                                        do {
                                            if ($eventStartTimestamp > $startTimestamp && $eventStartTimestamp <= $until) {
                                                $anEvent['DTSTART'] = date(self::DATE_TIME_FORMAT, $eventStartTimestamp) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '');
                                                $anEvent['DTSTART_array'][1] = $anEvent['DTSTART'];
                                                $anEvent['DTSTART_array'][2] = $eventStartTimestamp;
                                                $anEvent['DTEND_array']      = $anEvent['DTSTART_array'];
                                                $anEvent['DTEND_array'][2]  += $eventTimestampOffset;
                                                $anEvent['DTEND'] = date(
                                                    self::DATE_TIME_FORMAT,
                                                    $anEvent['DTEND_array'][2]
                                                ) . (($initialEndTimeZoneName === 'Z') ? 'Z' : '');
                                                $anEvent['DTEND_array'][1] = $anEvent['DTEND'];

                                                // Exclusions
                                                $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $yearRecurringOffset) {
                                                    return self::isExdateMatch($exdate, $anEvent, $yearRecurringOffset);
                                                });

                                                if (isset($anEvent['UID'])) {
                                                    $searchDate = $anEvent['DTSTART'];
                                                    if (isset($anEvent['DTSTART_array'][0]['TZID'])) {
                                                        $searchDate = sprintf(self::ICAL_DATE_TIME_TEMPLATE, $anEvent['DTSTART_array'][0]['TZID']) . $searchDate;
                                                    }

                                                    if (isset($this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                        $searchDateUtc = $this->iCalDateToUnixTimestamp($searchDate, true, true);
                                                        if (in_array($searchDateUtc, $this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                            $isExcluded = true;
                                                        }
                                                    }
                                                }

                                                if (!$isExcluded) {
                                                    $anEvent            = $this->processEventIcalDateTime($anEvent);
                                                    $recurrenceEvents[] = $anEvent;
                                                    $this->eventCount++;

                                                    // If RRULE[COUNT] is reached then break
                                                    if (isset($rrules['COUNT'])) {
                                                        $countNb++;

                                                        if ($countNb >= $countOrig) {
                                                            break 3;
                                                        }
                                                    }
                                                }
                                            }

                                            $eventStartTimestamp += self::SECONDS_IN_A_WEEK;
                                        } while ($eventStartTimestamp <= $lastDayTimestamp);
                                    }

                                    // Move forwards
                                    $recurringTimestamp = strtotime($offset, $recurringTimestamp);
                                }
                            } else {
                                $day = $initialStart->format('d');

                                // Step through years
                                while ($recurringTimestamp <= $until) {
                                    $yearRecurringTimestamp = $recurringTimestamp;

                                    // Adjust time zone from initial event
                                    $yearRecurringOffset = 0;
                                    if ($this->useTimeZoneWithRRules) {
                                        $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $yearRecurringTimestamp);
                                        $recurringTimeZone->setTimezone($initialStart->getTimezone());
                                        $yearRecurringOffset = $recurringTimeZone->getOffset();
                                        $yearRecurringTimestamp += $yearRecurringOffset;
                                    }

                                    $eventStartDescs = array();
                                    if (isset($rrules['BYMONTH']) && $rrules['BYMONTH'] !== '') {
                                        foreach ($bymonths as $bymonth) {
                                            array_push($eventStartDescs, "{$day} {$this->monthNames[$bymonth]} " . gmdate('Y H:i:s', $yearRecurringTimestamp));
                                        }
                                    } else {
                                        array_push($eventStartDescs, $day . gmdate(self::DATE_TIME_FORMAT_PRETTY, $yearRecurringTimestamp));
                                    }

                                    foreach ($eventStartDescs as $eventStartDesc) {
                                        $eventStartTimestamp = strtotime($eventStartDesc);

                                        if ($eventStartTimestamp > $startTimestamp && $eventStartTimestamp <= $until) {
                                            $anEvent['DTSTART'] = date(self::DATE_TIME_FORMAT, $eventStartTimestamp) . (($initialStartTimeZoneName === 'Z') ? 'Z' : '');
                                            $anEvent['DTSTART_array'][1] = $anEvent['DTSTART'];
                                            $anEvent['DTSTART_array'][2] = $eventStartTimestamp;
                                            $anEvent['DTEND_array']      = $anEvent['DTSTART_array'];
                                            $anEvent['DTEND_array'][2]  += $eventTimestampOffset;
                                            $anEvent['DTEND'] = date(
                                                self::DATE_TIME_FORMAT,
                                                $anEvent['DTEND_array'][2]
                                            ) . (($initialEndTimeZoneName === 'Z') ? 'Z' : '');
                                            $anEvent['DTEND_array'][1] = $anEvent['DTEND'];

                                            // Exclusions
                                            $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $yearRecurringOffset) {
                                                return self::isExdateMatch($exdate, $anEvent, $yearRecurringOffset);
                                            });

                                            if (isset($anEvent['UID'])) {
                                                $searchDate = $anEvent['DTSTART'];
                                                if (isset($anEvent['DTSTART_array'][0]['TZID'])) {
                                                    $searchDate = sprintf(self::ICAL_DATE_TIME_TEMPLATE, $anEvent['DTSTART_array'][0]['TZID']) . $searchDate;
                                                }

                                                if (isset($this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                    $searchDateUtc = $this->iCalDateToUnixTimestamp($searchDate, true, true);
                                                    if (in_array($searchDateUtc, $this->alteredRecurrenceInstances[$anEvent['UID']])) {
                                                        $isExcluded = true;
                                                    }
                                                }
                                            }

                                            if (!$isExcluded) {
                                                $anEvent            = $this->processEventIcalDateTime($anEvent);
                                                $recurrenceEvents[] = $anEvent;
                                                $this->eventCount++;

                                                // If RRULE[COUNT] is reached then break
                                                if (isset($rrules['COUNT'])) {
                                                    $countNb++;

                                                    if ($countNb >= $countOrig) {
                                                        break 2;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Move forwards
                                    $recurringTimestamp = strtotime($offset, $recurringTimestamp);
                                }
                            }

                            $recurrenceEvents    = $this->trimToRecurrenceCount($rrules, $recurrenceEvents);
                            $allRecurrenceEvents = array_merge($allRecurrenceEvents, $recurrenceEvents);
                            $recurrenceEvents    = array(); // Reset
                            break;
                    }
                }
            }

            $events = array_merge($events, $allRecurrenceEvents);

            $this->cal['VEVENT'] = $events;
        }
    }
1263859
public boolean insertIntoTheCurrentSlot() {
		if (!getVal(currentPos(), INTEGER).equals(EMPTY_CONST))
			return false;
		
		setVal(currentPos(), INUSE_CONST);
		return true;
	}
168048
private synchronized boolean shouldRetry(Throwable e) {
    boolean isIOException = e instanceof IOException
      || (e.getCause() != null && e.getCause() instanceof IOException);
    boolean hasRemainingRetries = retryCount < maxRetries;
    return isIOException && hasRemainingRetries;
  }
1043985
private void readRecurringData(ProjectCalendarException bce, Project.Calendars.Calendar.Exceptions.Exception exception)
   {
      RecurrenceType rt = getRecurrenceType(NumberHelper.getInt(exception.getType()));
      if (rt != null)
      {
         RecurringData rd = new RecurringData();
         rd.setStartDate(bce.getFromDate());
         rd.setFinishDate(bce.getToDate());
         rd.setRecurrenceType(rt);
         rd.setRelative(getRelative(NumberHelper.getInt(exception.getType())));
         rd.setOccurrences(NumberHelper.getInteger(exception.getOccurrences()));

         switch (rd.getRecurrenceType())
         {
            case DAILY:
            {
               rd.setFrequency(getFrequency(exception));
               break;
            }

            case WEEKLY:
            {
               rd.setWeeklyDaysFromBitmap(NumberHelper.getInteger(exception.getDaysOfWeek()), DAY_MASKS);
               rd.setFrequency(getFrequency(exception));
               break;
            }

            case MONTHLY:
            {
               if (rd.getRelative())
               {
                  rd.setDayOfWeek(Day.getInstance(NumberHelper.getInt(exception.getMonthItem()) - 2));
                  rd.setDayNumber(Integer.valueOf(NumberHelper.getInt(exception.getMonthPosition()) + 1));
               }
               else
               {
                  rd.setDayNumber(NumberHelper.getInteger(exception.getMonthDay()));
               }
               rd.setFrequency(getFrequency(exception));
               break;
            }

            case YEARLY:
            {
               if (rd.getRelative())
               {
                  rd.setDayOfWeek(Day.getInstance(NumberHelper.getInt(exception.getMonthItem()) - 2));
                  rd.setDayNumber(Integer.valueOf(NumberHelper.getInt(exception.getMonthPosition()) + 1));
               }
               else
               {
                  rd.setDayNumber(NumberHelper.getInteger(exception.getMonthDay()));
               }
               rd.setMonthNumber(Integer.valueOf(NumberHelper.getInt(exception.getMonth()) + 1));
               break;
            }
         }

         if (rd.getRecurrenceType() != RecurrenceType.DAILY || rd.getDates().length > 1)
         {
            bce.setRecurring(rd);
         }
      }
   }
1330593
static private void copyEventRecurrenceToModel(final EventRecurrence er,
                                                   RecurrenceModel model) {
        // Freq:
        switch (er.freq) {
            case EventRecurrence.DAILY:
                model.freq = RecurrenceModel.FREQ_DAILY;
                break;
            case EventRecurrence.MONTHLY:
                model.freq = RecurrenceModel.FREQ_MONTHLY;
                break;
            case EventRecurrence.YEARLY:
                model.freq = RecurrenceModel.FREQ_YEARLY;
                break;
            case EventRecurrence.WEEKLY:
                model.freq = RecurrenceModel.FREQ_WEEKLY;
                break;
            default:
                throw new IllegalStateException("freq=" + er.freq);
        }

        // Interval:
        if (er.interval > 0) {
            model.interval = er.interval;
        }

        // End:
        // End by count:
        model.endCount = er.count;
        if (model.endCount > 0) {
            model.end = RecurrenceModel.END_BY_COUNT;
        }

        // End by date:
        if (!TextUtils.isEmpty(er.until)) {
            if (model.endDate == null) {
                model.endDate = new Time();
            }

            try {
                model.endDate.parse(er.until);
            } catch (TimeFormatException e) {
                model.endDate = null;
            }

            // LIMITATION: The UI can only handle END_BY_DATE or END_BY_COUNT
            if (model.end == RecurrenceModel.END_BY_COUNT && model.endDate != null) {
                throw new IllegalStateException("freq=" + er.freq);
            }

            model.end = RecurrenceModel.END_BY_DATE;
        }

        // Weekly: repeat by day of week or Monthly: repeat by nth day of week
        // in the month
        Arrays.fill(model.weeklyByDayOfWeek, false);
        if (er.bydayCount > 0) {
            int count = 0;
            for (int i = 0; i < er.bydayCount; i++) {
                int dayOfWeek = EventRecurrence.day2TimeDay(er.byday[i]);
                model.weeklyByDayOfWeek[dayOfWeek] = true;

                if (model.freq == RecurrenceModel.FREQ_MONTHLY &&
                        isSupportedMonthlyByNthDayOfWeek(er.bydayNum[i])) {
                    // LIMITATION: Can handle only (one) weekDayNum in nth or last and only
                    // when
                    // monthly
                    model.monthlyByDayOfWeek = dayOfWeek;
                    model.monthlyByNthDayOfWeek = er.bydayNum[i];
                    model.monthlyRepeat = RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK;
                    count++;
                }
            }

            if (model.freq == RecurrenceModel.FREQ_MONTHLY) {
                if (er.bydayCount != 1) {
                    // Can't handle 1st Monday and 2nd Wed
                    throw new IllegalStateException("Can handle only 1 byDayOfWeek in monthly");
                }
                if (count != 1) {
                    throw new IllegalStateException(
                            "Didn't specify which nth day of week to repeat for a monthly");
                }
            }
        }

        // Monthly by day of month
        if (model.freq == RecurrenceModel.FREQ_MONTHLY) {
            if (er.bymonthdayCount == 1) {
                if (model.monthlyRepeat == RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK) {
                    throw new IllegalStateException(
                            "Can handle only by monthday or by nth day of week, not both");
                }
                model.monthlyByMonthDay = er.bymonthday[0];
                model.monthlyRepeat = RecurrenceModel.MONTHLY_BY_DATE;
            } else if (er.bymonthCount > 1) {
                // LIMITATION: Can handle only one month day
                throw new IllegalStateException("Can handle only one bymonthday");
            }
        }
    }
126411
@Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (checkedId == R.id.repeatMonthlyByNthDayOfMonth) {
            mModel.monthlyRepeat = RecurrenceModel.MONTHLY_BY_DATE;
        } else if (checkedId == R.id.repeatMonthlyByNthDayOfTheWeek) {
            mModel.monthlyRepeat = RecurrenceModel.MONTHLY_BY_NTH_DAY_OF_WEEK;
        }
        updateDialog();
    }
426016
public boolean checkAndIncrease() {

        long newTimestamp = System.currentTimeMillis();

        if (isShutdown) {
            if (newTimestamp > shutdownEndTime) {
                isShutdown = false;
                largeLimitCalls = 0;
                smallLimitCalls = 0;
            } else {
                return false;
            }
        }

        if (newTimestamp - smallLimitTimestamp > smallTimeFrame) {
            smallLimitCalls = 0;
            smallLimitTimestamp = newTimestamp;
        } else {
            if (smallLimitCalls >= smallCallLimit) {
                return false;
            } else {
                smallLimitCalls += 1;
            }
        }

        if (newTimestamp - largeLimitTimestamp > largeTimeFrame) {
            largeLimitCalls = 0;
            largeLimitTimestamp = newTimestamp;
        } else {
            if (largeLimitCalls >= largeCallsLimit) {
                isShutdown = true;
                shutdownEndTime = newTimestamp + shutdownPeriod;
                return false;
            } else {
                largeLimitCalls += 1;
            }
        }

        return true;
    }
233899
public boolean isEnlisted()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "isEnlisted");

        boolean retval = false;

        if (_currentTran != null)
        {
            retval = true;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "isEnlisted", "return="+retval);
        return retval;
    }
1208540
public final boolean isReadOnly() {
        Entry<?> entry = getEntry();
        Calendar calendar = entry.getCalendar();
        if (calendar != null) {
            return calendar.isReadOnly();
        }

        return false;
    }
1068638
@Override
  public boolean onTrigger() {
    List<Event<T>> windowEvents = null;
    List<T> expired = null;

    /*
     * scan the entire window to handle out of order events in
     * the case of time based windows.
     */
    windowEvents = scanEvents(true);
    expired = new ArrayList<>(expiredEvents);
    expiredEvents.clear();
    List<T> events = new ArrayList<>();
    List<T> newEvents = new ArrayList<>();
    for (Event<T> event : windowEvents) {
      events.add(event.get());
      if (!prevWindowEvents.contains(event)) {
        newEvents.add(event.get());
      }
    }
    prevWindowEvents.clear();
    if (!events.isEmpty()) {
      prevWindowEvents.addAll(windowEvents);
      LOG.fine(String.format("invoking windowLifecycleListener onActivation, [%d] events in "
          + "window.", events.size()));
      windowLifecycleListener.onActivation(events, newEvents, expired,
          evictionPolicy.getContext().getReferenceTime());
    } else {
      LOG.fine("No events in the window, skipping onActivation");
    }
    triggerPolicy.reset();
    return !events.isEmpty();
  }
251299
public boolean entryExists(UniqueKeyGenerator generator)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "entryExists", "GeneratorName="+generator.getName());

        boolean retval = false;

        if (_generators.containsKey(generator.getName()))
        {
            retval = true;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "entryExists", "retrun="+retval);
        return retval;
    }
808538
def is_volatile(self):
        

        hw = self.get_property('hw')
        return (
            (hw in (rdltypes.AccessType.rw, rdltypes.AccessType.rw1,
                    rdltypes.AccessType.w, rdltypes.AccessType.w1))
            or self.get_property('counter')
            or (self.get_property('next') is not None)
            or self.get_property('hwset')
            or self.get_property('hwclr')
        )
712112
public final GregorianCalendar getNextRunTime(Occurrence occurrence, boolean is_failed, int attempt_count, GregorianCalendar schedule_start, int run_count)
    {
        int failure_attempts = 0;
        if (is_failed && failure_schedule != null && attempt_count > 0)
        {
            GregorianCalendar next_run = failure_schedule.getNextRunTime(schedule_start, attempt_count - 1);
            if (next_run != null)
                return next_run;
            failure_attempts = failure_schedule.getSchedules().length;
        }

        return getAdjustedNextRunTime(occurrence, schedule_start, run_count + (attempt_count - failure_attempts), new GregorianCalendar());
    }
222821
def get_recurring_events(self, calendar_id, event_id, start_time, end_time, maxResults = None):
        ''''''
        es = []
        page_token = None
        while True:
            events = self.service.events().instances(calendarId = self.configured_calendar_ids[calendar_id], eventId = event_id, pageToken=page_token, timeMin = start_time, timeMax = end_time, maxResults = maxResults, showDeleted = False).execute()
            for event in events['items']:
                dt = None
                nb = DeepNonStrictNestedBunch(event)
                assert(not(nb._event))
                nb._event = event # keep the original event as returned in case we want to reuse it e.g. insert it into another calendar
                if nb.start.date:
                    dt = dateutil.parser.parse(nb.start.date + 'T00:00:00-08:00')
                elif nb.start.dateTime:
                    dt = dateutil.parser.parse(nb.start.dateTime)
                nb.datetime_o = dt
                nb.calendar_id = calendar_id
                es.append(nb)
            page_token = events.get('nextPageToken')
            if not page_token:
                break
        return es