2017 © Pedro Peláez
 

library recurr

PHP library for working with recurrence rules

image

simshaun/recurr

PHP library for working with recurrence rules

  • Tuesday, July 17, 2018
  • by simshaun
  • Repository
  • 32 Watchers
  • 753 Stars
  • 496,543 Installations
  • PHP
  • 16 Dependents
  • 0 Suggesters
  • 83 Forks
  • 27 Open issues
  • 56 Versions
  • 12 % Grown

The README.md

Recurr

tests Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Recurr is a PHP library for working with recurrence rules (RRULE) and converting them in to DateTime objects., (*2)

Recurr was developed as a precursor for a calendar with recurring events, and is heavily inspired by rrule.js., (*3)

Installing Recurr

The recommended way to install Recurr is through Composer., (*4)

composer require simshaun/recurr

Using Recurr

Creating RRULE rule objects

You can create a new Rule object by passing the (RRULE) string or an array with the rule parts, the start date, end date (optional) and timezone., (*5)

$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., (*6)

$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

$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., (*7)

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:, (*8)

  • 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,, (*9)

$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., (*10)

Post-Transformation RecurrenceCollection Filters

RecurrenceCollection provides the following chainable helper methods to filter out recurrences:, (*11)

  • 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,, (*12)

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 class., (*13)

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., (*14)

$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)., (*15)

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

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

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:, (*16)

$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

Feel free to comment or make pull requests. Please include tests with PRs., (*17)

License

Recurr is licensed under the MIT License. See the LICENSE file for details., (*18)

The Versions

17/07 2018

dev-master

9999999-dev https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

16/07 2018

v3.0.6

3.0.6.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

17/01 2018

v3.0.5

3.0.5.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

17/01 2018

v3.0.4

3.0.4.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

13/11 2017

v3.0.3

3.0.3.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

04/08 2017

v3.0.2

3.0.2.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

19/07 2017

v3.0.1

3.0.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

14/07 2017

v3.0

3.0.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

05/05 2017

v2.2.3

2.2.3.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

05/05 2017

v2.2.2

2.2.2.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

05/05 2017

v2.2.1

2.2.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

02/03 2017

v2.2

2.2.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

19/12 2016

v2.1

2.1.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

02/12 2016

v2.0

2.0.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

01/12 2016

v1.3

1.3.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

22/09 2016

v1.2

1.2.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

21/09 2016

v1.1

1.1.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

11/08 2016

v1.0.1

1.0.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

11/08 2016

v1.0

1.0.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

11/08 2016

v0.6.4

0.6.4.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

28/07 2016

v0.6.3

0.6.3.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

06/07 2016

v0.6.2

0.6.2.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/12 2015

v0.6.1

0.6.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/12 2015

v0.6

0.6.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/12 2015

v0.5.1

0.5.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/12 2015

v0.5

0.5.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/12 2015

dev-issue-71-test

dev-issue-71-test https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/12 2015

v0.4.9

0.4.9.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

01/10 2015

v0.4.8

0.4.8.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

05/07 2015

v0.4.7

0.4.7.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

05/07 2015

v0.4.5

0.4.5.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

05/05 2015

v0.4.4

0.4.4.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/01 2015

v0.4.3

0.4.3.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

17/12 2014

v0.4.2

0.4.2.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

16/12 2014

v0.4.1

0.4.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

16/12 2014

v0.4

0.4.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

01/12 2014

v0.3.5

0.3.5.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

01/12 2014

v0.3.3

0.3.3.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

01/12 2014

v0.3.4

0.3.4.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

29/09 2014

v0.3.2

0.3.2.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

09/09 2014

v0.3.1

0.3.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

18/06 2014

v0.3

0.3.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

18/06 2014

v0.2.2

0.2.2.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

10/06 2014

v0.2.1

0.2.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

08/06 2014

v0.2

0.2.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

 

The Development Requires

events recurring rrule recurrence dates

16/03 2014

v0.1.9

0.1.9.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

23/02 2014

v0.1.8

0.1.8.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

15/01 2014

v0.1.7

0.1.7.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

10/01 2014

v0.1.6

0.1.6.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

07/01 2014

v0.1.5

0.1.5.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

14/10 2013

v0.1.4

0.1.4.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

01/10 2013

v0.1.3

0.1.3.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

31/07 2013

v0.1.2

0.1.2.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

10/07 2013

v0.1.1

0.1.1.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

14/06 2013

v0.1

0.1.0.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates

14/06 2013

v0.4.6

0.4.6.0 https://github.com/simshaun/recurr

PHP library for working with recurrence rules

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

events recurring rrule recurrence dates