PHPackages                             af/rrule - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. af/rrule

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

af/rrule
========

PHP library for working with recurrence rules

0171PHP

Since Aug 25Pushed 10y ago2 watchersCompare

[ Source](https://github.com/afernandes465/rrule)[ Packagist](https://packagist.org/packages/af/rrule)[ RSS](/packages/af-rrule/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Recurr [![Build Status](https://camo.githubusercontent.com/cd6968215e4f70d04750f2d01df7e1c0e945a805a801f18441c4979df9378fd0/68747470733a2f2f7472617669732d63692e6f72672f73696d736861756e2f7265637572722e706e67)](https://travis-ci.org/simshaun/recurr.png) [![Latest Stable Version](https://camo.githubusercontent.com/04ee03737b5421f9cd9b5739ff0da8133e7c39fa93b110d6e28378b0ef339769/68747470733a2f2f706f7365722e707567782e6f72672f73696d736861756e2f7265637572722f762f737461626c652e737667)](https://packagist.org/packages/simshaun/recurr) [![Total Downloads](https://camo.githubusercontent.com/81ccd3bddf7c59b040c3d9427da73dad85576bd961b51f72ce1227d5ffe79dd1/68747470733a2f2f706f7365722e707567782e6f72672f73696d736861756e2f7265637572722f646f776e6c6f6164732e737667)](https://packagist.org/packages/simshaun/recurr) [![Latest Unstable Version](https://camo.githubusercontent.com/1f946f1dc70032532d7ad9e8aba3ecea0797c0f5a2b288e94e9a72b14fa2aeaf/68747470733a2f2f706f7365722e707567782e6f72672f73696d736861756e2f7265637572722f762f756e737461626c652e737667)](https://packagist.org/packages/simshaun/recurr) [![License](https://camo.githubusercontent.com/9fb490ac57cec54cd82988e9f6e408ce44d8e38b86a3a920796521a608059701/68747470733a2f2f706f7365722e707567782e6f72672f73696d736861756e2f7265637572722f6c6963656e73652e737667)](https://packagist.org/packages/simshaun/recurr)
=========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#recurr-----)

Recurr is a PHP library for working with recurrence rules ([RRULE](http://tools.ietf.org/html/rfc2445)) and converting them in to DateTime objects.

Recurr was developed as a precursor for a calendar with recurring events, and is heavily inspired by [rrule.js](https://github.com/jkbr/rrule).

Installation
------------

[](#installation)

Recurr is hosted on [Packagist](https://packagist.org), meaning you can install it with [Composer](https://getcomposer.org/):

`composer require af/rrule:~1.0`

or add

`"af/rrule" : "~1.0"`

to the require section of your application's composer.json file.

RRULE to DateTime objects
-------------------------

[](#rrule-to-datetime-objects)

```
$timezone    = 'America/New_York';
$startDate   = new \DateTime('2013-06-12 20:00:00', new \DateTimeZone($timezone));
$endDate     = new \DateTime('2013-06-14 20:00:00', new \DateTimeZone($timezone)); // Optional
$rule        = new \Recurr\Rule('FREQ=MONTHLY;COUNT=5', $startDate, $endDate, $timezone);
$transformer = new \Recurr\Transformer\ArrayTransformer();

print_r($transformer->transform($rule));
```

1. `$transformer->transform(...)` returns a `RecurrenceCollection` of `Recurrence` objects.
2. Each `Recurrence` has `getStart()` and `getEnd()` methods that return a `\DateTime` object.
3. If the transformed `Rule` lacks an end date, `getEnd()` will return a `\DateTime` object equal to that of `getStart()`.

> Note: The transformer has a "virtual" limit (default 732) on the number of objects it generates. This prevents the script from crashing on an infinitely recurring rule. You can change the virtual limit in the call to `transform` or the `ArrayTransformer` constructor.

### Transformation Constraints

[](#transformation-constraints)

Constraints (`\Recurr\Transformer\ConstraintInterface`) are used by the ArrayTransformer to allow or prevent certain dates from being added to a `RecurrenceCollection`. Recurr provides the following constraints:

- `AfterConstraint(\DateTime $after, $inc = false)`
- `BeforeConstraint(\DateTime $before, $inc = false)`
- `BetweenConstraint(\DateTime $after, \DateTime $before, $inc = false)`

`$inc` defines what happens if `$after` or `$before` are themselves recurrences. If `$inc = true`, they will be included in the collection. For example,

```
$startDate   = new \DateTime('2014-06-17 04:00:00');
$rule        = new \Recurr\Rule('FREQ=MONTHLY;COUNT=5', $startDate);
$transformer = new \Recurr\Transformer\ArrayTransformer();

$constraint = new \Recurr\Transformer\Constraint\BeforeConstraint(new \DateTime('2014-08-01 00:00:00'));
print_r($transformer->transform($rule, null, $constraint));
```

> Note: If building your own constraint, it is important to know that dates which do not meet the constraint's requirements do **not** count toward the transformer's virtual limit. If you manually set your constraint's `$stopsTransformer` property to `false`, the transformer *might* crash via an infinite loop. See the `BetweenConstraint` for an example on how to prevent that.

### Post-Transformation `RecurrenceCollection` Filters

[](#post-transformation-recurrencecollection-filters)

`RecurrenceCollection` provides the following **chainable** helper methods to filter out recurrences:

- `startsBetween(\DateTime $after, \DateTime $before, $inc = false)`
- `startsBefore(\DateTime $before, $inc = false)`
- `startsAfter(\DateTime $after, $inc = false)`
- `endsBetween(\DateTime $after, \DateTime $before, $inc = false)`
- `endsBefore(\DateTime $before, $inc = false)`
- `endsAfter(\DateTime $after, $inc = false)`

`$inc` defines what happens if `$after` or `$before` are themselves recurrences. If `$inc = true`, they will be included in the filtered collection. For example,

```
pseudo...
2014-06-01 startsBetween(2014-06-01, 2014-06-20) // false
2014-06-01 startsBetween(2014-06-01, 2014-06-20, true) // true

```

> Note: `RecurrenceCollection` extends the Doctrine project's [ArrayCollection](https://github.com/doctrine/collections/blob/master/lib/Doctrine/Common/Collections/ArrayCollection.php) class.

RRULE to Text
-------------

[](#rrule-to-text)

Recurr supports transforming some recurrence rules into human readable text. This feature is still in beta and only supports yearly, monthly, weekly, and daily frequencies.

```
$rule = new Rule('FREQ=YEARLY;INTERVAL=2;COUNT=3;', new \DateTime());

$textTransformer = new TextTransformer();
echo $textTransformer->transform($rule);
```

If you need more than English you can pass in a translator with one of the supported locales (currently en, de, fr, it).

```
$rule = new Rule('FREQ=YEARLY;INTERVAL=2;COUNT=3;', new \DateTime());

$textTransformer = new TextTransformer(
    new \Recurr\Transformer\Translator('de')
);
echo $textTransformer->transform($rule);
```

Warnings
--------

[](#warnings)

- Monthly recurring rules: **If your start date is on the 29th, 30th, or 31st, Recurr will skip the months that have less than that number of days.** This behavior is configurable:

```
$timezone    = 'America/New_York';
$startDate   = new \DateTime('2013-01-31 20:00:00', new \DateTimeZone($timezone));
$rule        = new \Recurr\Rule('FREQ=MONTHLY;COUNT=5', $startDate, null, $timezone);
$transformer = new \Recurr\Transformer\ArrayTransformer();

$transformerConfig = new \Recurr\Transformer\ArrayTransformerConfig();
$transformerConfig->enableLastDayOfMonthFix();
$transformer->setConfig($transformerConfig);

print_r($transformer->transform($rule));

/* Recurrences:
 * 2013-01-31
 * 2013-02-28
 * 2013-03-31
 * 2013-04-30
 * 2013-05-31
 */
```

Contribute
----------

[](#contribute)

Recurr is still in beta, and is most likely not 100% free of bugs. Feel free to comment or make pull requests. Please include tests with PRs.

License
-------

[](#license)

Recurr is licensed under the MIT License. See the LICENSE file for details.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fd5c01bec7ed689bfaef63215496f9110c2d8e28c38c1c6b15f0819cbe88fed?d=identicon)[afernandes465](/maintainers/afernandes465)

### Embed Badge

![Health badge](/badges/af-rrule/health.svg)

```
[![Health](https://phpackages.com/badges/af-rrule/health.svg)](https://phpackages.com/packages/af-rrule)
```

###  Alternatives

[laminas/laminas-stdlib

SPL extensions, array utilities, error handlers, and more

238109.7M518](/packages/laminas-laminas-stdlib)[cknow/laravel-money

Laravel Money

1.0k4.8M31](/packages/cknow-laravel-money)[fresh/datetime

PHP library that provides additional functions for processing dates &amp; times.

18621.6k3](/packages/fresh-datetime)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
