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

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

selfworks/recurr
================

PHP library for working with recurrence rules

v3.1.0(7y ago)04.2k2MITPHPPHP &gt;=5.6.3

Since Jun 14Pushed 6y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (60)Used By (0)

Recurr [![Build Status](https://camo.githubusercontent.com/f4b42069163ea4a04903a04a7eafe6300ee743da4d3c831e972c95f586c4380e/68747470733a2f2f7472617669732d63692e6f72672f73656c66776f726b732f7265637572722e706e67)](https://travis-ci.org/selfworks/recurr.png) [![Latest Stable Version](https://camo.githubusercontent.com/7ebf9f5bb5c01cc5039b146b19a49fa0c68b7bc75a352e604e881bd2de4e62cb/68747470733a2f2f706f7365722e707567782e6f72672f73656c66776f726b732f7265637572722f762f737461626c652e737667)](https://packagist.org/packages/selfworks/recurr) [![Total Downloads](https://camo.githubusercontent.com/c7d63b9ec61048b4031a74c02e587ddcd86e0a1ed4e299fb34e9718bebf8e6b2/68747470733a2f2f706f7365722e707567782e6f72672f73656c66776f726b732f7265637572722f646f776e6c6f6164732e737667)](https://packagist.org/packages/selfworks/recurr) [![Latest Unstable Version](https://camo.githubusercontent.com/35149be204fb566270d7ac8ba53fa3d0ba8e89678cc2caa10a712c698d4b6bfa/68747470733a2f2f706f7365722e707567782e6f72672f73656c66776f726b732f7265637572722f762f756e737461626c652e737667)](https://packagist.org/packages/selfworks/recurr) [![License](https://camo.githubusercontent.com/6c606343ede1ad655ca9d48315ab48c3306aca75120de922a3f95beef0e4646e/68747470733a2f2f706f7365722e707567782e6f72672f73656c66776f726b732f7265637572722f6c6963656e73652e737667)](https://packagist.org/packages/selfworks/recurr)
========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#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 selfworks/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/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 *(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 file for details.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 71% 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 ~34 days

Recently: every ~18 days

Total

58

Last Release

2786d ago

Major Versions

v0.6.4 → v1.02016-08-11

v1.3 → v2.02016-12-02

v2.2.3 → v3.02017-07-14

PHP version history (3 changes)v0.4.6PHP &gt;=5.3.0

v3.0PHP &gt;=5.5.0

v3.0.9PHP &gt;=5.6.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/97bd01c88813abc663e8ad59b46d5d36e1a755ba9253c2442d3f7be2d2caf66b?d=identicon)[selfworks](/maintainers/selfworks)

---

Top Contributors

[![simshaun](https://avatars.githubusercontent.com/u/379519?v=4)](https://github.com/simshaun "simshaun (103 commits)")[![bobicloudvision](https://avatars.githubusercontent.com/u/69676022?v=4)](https://github.com/bobicloudvision "bobicloudvision (8 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)")[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (3 commits)")[![avr](https://avatars.githubusercontent.com/u/347482?v=4)](https://github.com/avr "avr (2 commits)")[![jonny-no1](https://avatars.githubusercontent.com/u/282458?v=4)](https://github.com/jonny-no1 "jonny-no1 (2 commits)")[![emnsen](https://avatars.githubusercontent.com/u/5148536?v=4)](https://github.com/emnsen "emnsen (1 commits)")[![houseoftech](https://avatars.githubusercontent.com/u/297458?v=4)](https://github.com/houseoftech "houseoftech (1 commits)")[![inghamn](https://avatars.githubusercontent.com/u/630282?v=4)](https://github.com/inghamn "inghamn (1 commits)")[![inmula](https://avatars.githubusercontent.com/u/21057453?v=4)](https://github.com/inmula "inmula (1 commits)")[![jarofgreen](https://avatars.githubusercontent.com/u/85656?v=4)](https://github.com/jarofgreen "jarofgreen (1 commits)")[![JoakimHising](https://avatars.githubusercontent.com/u/1328192?v=4)](https://github.com/JoakimHising "JoakimHising (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)")[![ScullWM](https://avatars.githubusercontent.com/u/1017746?v=4)](https://github.com/ScullWM "ScullWM (1 commits)")[![a-am](https://avatars.githubusercontent.com/u/976370?v=4)](https://github.com/a-am "a-am (1 commits)")[![spapad](https://avatars.githubusercontent.com/u/7470875?v=4)](https://github.com/spapad "spapad (1 commits)")[![agonirena](https://avatars.githubusercontent.com/u/443969?v=4)](https://github.com/agonirena "agonirena (1 commits)")

---

Tags

eventsrecurringrrulerecurrencedates

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[simshaun/recurr

PHP library for working with recurrence rules

1.6k15.7M40](/packages/simshaun-recurr)[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)

PHPackages © 2026

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