PHPackages                             simshaun/recurr - 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. simshaun/recurr

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

simshaun/recurr
===============

PHP library for working with recurrence rules

v6.0.0(7mo ago)1.6k15.7M—9.5%152[37 issues](https://github.com/simshaun/recurr/issues)[14 PRs](https://github.com/simshaun/recurr/pulls)20MITPHPPHP &gt;=8.4CI failing

Since Jun 14Pushed 7mo ago32 watchersCompare

[ Source](https://github.com/simshaun/recurr)[ Packagist](https://packagist.org/packages/simshaun/recurr)[ Docs](https://github.com/simshaun/recurr)[ RSS](/packages/simshaun-recurr/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (71)Used By (20)

Recurr
======

[](#recurr)

[![tests](https://github.com/simshaun/recurr/workflows/tests/badge.svg)](https://github.com/simshaun/recurr/actions)[![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 is a PHP library for working with recurrence rules ([RRULE](https://tools.ietf.org/html/rfc5545)) 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).

Installing Recurr
-----------------

[](#installing-recurr)

The recommended way to install Recurr is through [Composer](http://getcomposer.org).

```
composer require simshaun/recurr
```

Using Recurr
------------

[](#using-recurr)

### Creating RRULE rule objects

[](#creating-rrule-rule-objects)

You can create a new Rule object by passing the ([RRULE](https://tools.ietf.org/html/rfc5545)) string or an array with the rule parts, the start date, end date (optional) and timezone.

```
$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);
```

You can also use chained methods to build your rule programmatically and get the resulting RRULE.

```
$rule = (new \Recurr\Rule)
    ->setStartDate($startDate)
    ->setTimezone($timezone)
    ->setFreq('DAILY')
    ->setByDay(['MO', 'TU'])
    ->setUntil(new \DateTime('2017-12-31'))
;

echo $rule->getString(); //FREQ=DAILY;UNTIL=20171231T000000;BYDAY=MO,TU
```

### RRULE to DateTime objects

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

```
$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 with an `ArrayTransformerConfig` object that you pass to `ArrayTransformer`.

### Transformation Constraints

[](#transformation-constraints)

Constraints 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, $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/2.3.x/src/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 *(see translations folder)*.

```
$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**By default, if your start date is on the 29th, 30th, or 31st, Recurr will skip following months that don't have at least that many days. *(e.g. Jan 31 + 1 month = March)*

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));
// 2013-01-31, 2013-02-28, 2013-03-31, 2013-04-30, 2013-05-31
```

Contribute
----------

[](#contribute)

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](./LICENSE) file for details.

###  Health Score

73

—

ExcellentBetter than 100% of packages

Maintenance63

Regular maintenance activity

Popularity73

Solid adoption and visibility

Community46

Growing community involvement

Maturity95

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.1% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~67 days

Recently: every ~371 days

Total

68

Last Release

227d ago

Major Versions

v1.3 → v2.02016-12-02

v2.2.3 → v3.02017-07-14

v3.1.1 → v4.02019-02-24

v4.0.5 → v5.0.02021-09-09

v5.0.3 → v6.0.02025-10-04

PHP version history (4 changes)v0.1PHP &gt;=5.3.0

v3.0PHP &gt;=5.5.0

v5.0.0PHP ^7.2||^8.0

v6.0.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/10caac605a70fa152a922a01b4fd607c86051ebad867bbcec458e27f98df0421?d=identicon)[simshaun](/maintainers/simshaun)

---

Top Contributors

[![simshaun](https://avatars.githubusercontent.com/u/379519?v=4)](https://github.com/simshaun "simshaun (123 commits)")[![ankurk91](https://avatars.githubusercontent.com/u/6111524?v=4)](https://github.com/ankurk91 "ankurk91 (6 commits)")[![fentie](https://avatars.githubusercontent.com/u/273815?v=4)](https://github.com/fentie "fentie (5 commits)")[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (4 commits)")[![williamdes](https://avatars.githubusercontent.com/u/7784660?v=4)](https://github.com/williamdes "williamdes (3 commits)")[![libertjeremy](https://avatars.githubusercontent.com/u/5872294?v=4)](https://github.com/libertjeremy "libertjeremy (3 commits)")[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (3 commits)")[![jonny-no1](https://avatars.githubusercontent.com/u/282458?v=4)](https://github.com/jonny-no1 "jonny-no1 (2 commits)")[![avr](https://avatars.githubusercontent.com/u/347482?v=4)](https://github.com/avr "avr (2 commits)")[![mandclu-acquia](https://avatars.githubusercontent.com/u/89647003?v=4)](https://github.com/mandclu-acquia "mandclu-acquia (2 commits)")[![janlanger](https://avatars.githubusercontent.com/u/415695?v=4)](https://github.com/janlanger "janlanger (1 commits)")[![a-am](https://avatars.githubusercontent.com/u/976370?v=4)](https://github.com/a-am "a-am (1 commits)")[![jdelaune](https://avatars.githubusercontent.com/u/627362?v=4)](https://github.com/jdelaune "jdelaune (1 commits)")[![JoakimHising](https://avatars.githubusercontent.com/u/1328192?v=4)](https://github.com/JoakimHising "JoakimHising (1 commits)")[![mhaamann](https://avatars.githubusercontent.com/u/1766107?v=4)](https://github.com/mhaamann "mhaamann (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![pmeth](https://avatars.githubusercontent.com/u/1241034?v=4)](https://github.com/pmeth "pmeth (1 commits)")[![robinvda](https://avatars.githubusercontent.com/u/9365082?v=4)](https://github.com/robinvda "robinvda (1 commits)")[![romainnorberg](https://avatars.githubusercontent.com/u/7681951?v=4)](https://github.com/romainnorberg "romainnorberg (1 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (1 commits)")

---

Tags

phprecurrencerecurrence-rulesrecurring-eventseventsrecurringrrulerecurrencedates

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/simshaun-recurr/health.svg)

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

###  Alternatives

[doctrine/event-manager

The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.

6.1k501.1M115](/packages/doctrine-event-manager)[rlanvin/php-rrule

Lightweight and fast recurrence rules for PHP (RFC 5545)

69810.6M39](/packages/rlanvin-php-rrule)[psr/event-dispatcher

Standard interfaces for event handling.

2.3k618.8M865](/packages/psr-event-dispatcher)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k69.8M225](/packages/laminas-laminas-eventmanager)[chelout/laravel-relationship-events

Missing relationship events for Laravel

5252.3M17](/packages/chelout-laravel-relationship-events)[tplaner/when

Date/Calendar recursion library.

5261.0M5](/packages/tplaner-when)

PHPackages © 2026

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