2015-06-26 16:02:29 +02:00
# RRULE for PHP
2017-02-24 19:49:37 +01:00
Lightweight and fast implementation of recurrence rules for PHP (`RRULE` from RFC 5545), to easily calculate recurring/repeating dates and events (such as in a calendar).
This library started as a port of [python-dateutil ](https://labix.org/python-dateutil ).
2015-06-26 20:49:52 +02:00
2020-12-09 22:10:34 +01:00
[![Build status ](https://github.com/rlanvin/php-rrule/workflows/Tests/badge.svg )](https://github.com/rlanvin/php-rrule/actions)
2016-03-23 17:49:37 +01:00
[![Latest Stable Version ](https://poser.pugx.org/rlanvin/php-rrule/v/stable )](https://packagist.org/packages/rlanvin/php-rrule)
2016-11-11 19:38:59 +01:00
[![Total Downloads ](https://poser.pugx.org/rlanvin/php-rrule/downloads )](https://packagist.org/packages/rlanvin/php-rrule)
2015-06-26 20:49:52 +02:00
## Basic example
```php
use RRule\RRule;
$rrule = new RRule([
'FREQ' => 'MONTHLY',
'INTERVAL' => 1,
'DTSTART' => '2015-06-01',
'COUNT' => 6
]);
2019-09-01 20:50:21 +02:00
foreach ($rrule as $occurrence) {
2016-12-06 17:27:50 +01:00
echo $occurrence->format('D d M Y'),", ";
2015-06-26 20:49:52 +02:00
}
2016-12-06 17:27:50 +01:00
// Mon 01 Jun 2015, Wed 01 Jul 2015, Sat 01 Aug 2015, Tue 01 Sep 2015, Thu 01 Oct 2015, Sun 01 Nov 2015
2015-07-08 11:40:45 +02:00
echo $rrule->humanReadable(),"\n";
// monthly on the 1st of the month, starting from 01/06/2015, 6 times
2015-06-26 20:49:52 +02:00
```
2016-12-06 17:40:23 +01:00
Complete documentation and more examples are available in [the wiki ](https://github.com/rlanvin/php-rrule/wiki ).
2015-06-26 20:49:52 +02:00
## Requirements
2019-01-13 11:00:43 +01:00
- PHP >= 5.6
2015-07-08 11:40:45 +02:00
- [intl extension ](http://php.net/manual/en/book.intl.php ) is recommended for `humanReadable()` but not strictly required
2015-06-26 20:49:52 +02:00
## Installation
The recommended way is to install the lib [through Composer ](http://getcomposer.org/ ).
2016-12-06 17:40:23 +01:00
Simply run `composer require rlanvin/php-rrule` for it to be automatically installed and included in your `composer.json` .
2016-12-06 17:27:50 +01:00
2015-06-26 20:49:52 +02:00
Now you can use the autoloader, and you will have access to the library:
```php
require 'vendor/autoload.php';
```
2015-07-08 11:40:45 +02:00
## Documentation
2016-12-06 17:27:50 +01:00
Complete documentation is available in [the wiki ](https://github.com/rlanvin/php-rrule/wiki ).
You will also find useful information in the [RFC 5545 section 3.3.10 ](https://tools.ietf.org/html/rfc5545#section-3.3.10 ).
2015-07-08 11:40:45 +02:00
## Contribution
Feel free to contribute! Just create a new issue or a new pull request.
2019-01-14 14:09:43 +01:00
The coding style is (mostly) PSR-2, but with tabs.
2021-07-04 12:45:11 +02:00
### Translation
2021-05-07 14:59:35 +02:00
2021-10-25 16:31:52 +02:00
Use `./bin/review_translations.php --locale <locale>` to print a list of examples using the locale specified (default is English).
Use `./bin/review_translations.php --rule "<rule>"` to test a specific rule in all available locales.
2021-05-07 14:59:35 +02:00
2015-06-26 20:49:52 +02:00
## Note
I started this library because I wasn't happy with the existing implementations
2015-07-01 11:23:39 +02:00
in PHP, so I thought it would be a good learning project to port the
2015-06-26 21:10:46 +02:00
python-dateutil rrule implementation into PHP.
2015-06-26 20:49:52 +02:00
2015-07-01 11:23:39 +02:00
The Python lib was a bit difficult to understand because the algorithms
2015-06-26 21:10:46 +02:00
are not commented and the variables are very opaque (I'm looking at
you `lno1wkst` ). I tried to comment and explain as much of the algorithm as possible
in this PHP port, so feel free to check the code if you're interested.
2015-06-26 20:49:52 +02:00
The lib differs from the python version in various aspects, notably in the
2015-07-01 11:23:39 +02:00
respect of the RFC. This version is a bit strictier and will not accept many
2015-06-26 20:49:52 +02:00
non-compliant combinations of rule parts, that the python version otherwise accepts.
There are also some additional features in this version.
## License
This library is released under the MIT License.