Download the PHP package simshaun/recurr without Composer
On this page you can find all versions of the php package simshaun/recurr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download simshaun/recurr
More information about simshaun/recurr
Files in simshaun/recurr
Package recurr
Short Description PHP library for working with recurrence rules
License MIT
Homepage https://github.com/simshaun/recurr
Rated 5.00 based on 1 reviews
Informations about the package recurr
Recurr
Recurr is a PHP library for working with recurrence rules (RRULE) 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.
Installing Recurr
The recommended way to install Recurr is through Composer.
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.
You can also use chained methods to build your rule programmatically and get the resulting RRULE.
RRULE to DateTime objects
$transformer->transform(...)
returns aRecurrenceCollection
ofRecurrence
objects.- Each
Recurrence
hasgetStart()
andgetEnd()
methods that return a\DateTime
object. - If the transformed
Rule
lacks an end date,getEnd()
will return a\DateTime
object equal to that ofgetStart()
.
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 toArrayTransformer
.
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,
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 tofalse
, the transformer might crash via an infinite loop. See theBetweenConstraint
for an example on how to prevent that.
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 class.
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.
If you need more than English you can pass in a translator with one of the supported locales (see translations folder).
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:
Contribute
Feel free to comment or make pull requests. Please include tests with PRs.
License
Recurr is licensed under the MIT License. See the LICENSE file for details.