Skip to content
rlanvin edited this page Feb 25, 2017 · 18 revisions

This library offers a small, complete, and very fast implementation of the recurrence rules documented in the iCalendar RFC (RFC 5545). It allows you to work with recurring dates and events very easily. It is heavily based on python-dateutil.

Introduction

A recurrence rule (RRule) is represented by an immutable object which can be traversed to obtain all occurrences. Occurrences are DateTime objects.

RRule are defined in RFC 5545 section 3.3.10. You should definitely take a look to understand how it works. This documentation focuses on the specifics of this PHP library.

Example: Every first Monday of the month, in 2016.

$rrule = new RRule\RRule([
    'FREQ' => 'MONTHLY',
    'INTERVAL' => 1,
    'BYDAY' => '1MO',
    'DTSTART' => '2016-01-01',
    'UNTIL' => '2016-12-31'
]);

foreach ($rrule as $occurrence ) {
	echo $occurrence->format('Y-m-d'),"\n";
}

// 2016-01-04
// 2016-02-01
// 2016-03-07
// 2016-04-04
// 2016-05-02
// 2016-06-06
// 2016-07-04
// 2016-08-01
// 2016-09-05
// 2016-10-03
// 2016-11-07
// 2016-12-05

Classes

  • RRule: The base class that implements a RRULE string and calculates occurrences.
  • RSet: A recurrence set to combine multiple RRULE, EXRULE, RDATE and EXDATE. (version >= 1.1)

Interface

  • RRuleInterface: Any RRule or RSet object will implement this interface and have these methods. (version >= 1.1)

More documentation

If you can't find what you are looking for here, check:

Clone this wiki locally