Skip to content

RRuleInterface

rlanvin edited this page Mar 31, 2016 · 12 revisions

Any RRule or RSet object will implement this interface and have the following methods.

Methods

isFinite() and isInfinite()

(version >= 1.1)

Indicate whether or not the rule has an end (count or until), or is infinite.

Infinite rules cannot be counted, and you cannot get all occurrences as a array.

count()

Returns the number of occurrences, for finite rule only. This method will throw a LogicException if the rule has not COUNT or UNTIL part, as there is an infinity of occurrences.

A RRule object implements the Countable interface, meaning that you can call count($rrule) or $rrule->count().

getOccurrences()

Returns an array of all occurrences, for finite rules only. This method will throw a LogicException if the rule has not COUNT or UNTIL part, as there is an infinity of occurrences.

getOccurrencesBetween($begin, $end)

Returns an array of all occurrences between $begin and $end (included). Both dates can be given as a string understandable by PHP's DateTime constructor (for example 2015-07-01 14:46:30) a UNIX Timestamp (as int) or a DateTime object, or null.

  • If $begin is null this method will return all occurrences before $end.
  • If $end is null this method will return all occurrences after $begin. If the rule is infinite (no COUNT or UNTIL) it will throw a LogicException.
  • If both are null this method is the same as getOccurrences()

Note: If you are working with events, remember that there is no notion of duration. In other words, this method will returns the events that start between $begin and $end, but not the events that started before $begin and might still be ongoing due to their duration. If you want the later behavior, you should first subtract duration from $begin, to get the occurrences between "begin - duration" and "end".

occursAt($datetime)

Returns true if $datetime is an occurrence of the rule, or false otherwise. $datetime can be a string understandable by PHP's DateTime constructor (for example 2015-07-01 14:46:30) a UNIX Timestamp (as int) or a DateTime object.

Note: If you are working with events, remember that there is no notion of duration. In other words, this method will tell you if a event starts as $datetime, but not if an event is still ongoing at $datetime. If you want the later behavior, you should call getOccurencesBetween() with "datetime - duration" and "datetime".

Note

The RRule interface extends the following interfaces: Iterator, ArrayAccess and Countable.

Clone this wiki locally