1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2024-12-01 08:24:10 +01:00
This library offers a small, complete, and very fast, implementation of the recurrence rules documented in the iCalendar RFC. It is heavily based on python-dateutil.
Go to file
Craig Heydenburg f7bcad3538
Fix namespace on return type
phpstan interprets the namespace RRule and so turn the return type into RRule\DateTimeInterface which of course doesn't exist.
2023-02-22 09:36:35 +01:00
.github/workflows Fix compatibility with PHP 8.1 (#100) 2021-10-06 13:18:34 +02:00
bin Update examples rules in review_translations script 2021-07-04 16:23:13 +02:00
src Fix namespace on return type 2023-02-22 09:36:35 +01:00
tests Fix #120 Reset time to midnight to fix timezone offsets. 2023-01-06 11:01:00 +01:00
.gitattributes Exclude files from dist package 2022-08-04 08:48:42 +02:00
.gitignore Add remove/clear functions for ExDates and RDates (#66) 2019-03-17 10:45:34 +01:00
CHANGELOG.md Update Changelog for 2.4.0 2023-01-06 11:19:10 +01:00
composer.json Add tests for PHP 8.0 2020-12-09 23:01:45 +01:00
LICENSE Updating README, LICENSE and comments 2015-06-26 22:10:46 +03:00
phpunit.xml.dist Initial commit 2015-06-24 19:28:25 +03:00
README.md Update Changelog for release 2.3.0 2021-10-25 16:31:52 +02:00

RRULE for PHP

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.

Build status Latest Stable Version Total Downloads

Basic example

use RRule\RRule;

$rrule = new RRule([
	'FREQ' => 'MONTHLY',
	'INTERVAL' => 1,
	'DTSTART' => '2015-06-01',
	'COUNT' => 6
]);

foreach ($rrule as $occurrence) {
	echo $occurrence->format('D d M Y'),", ";
}
// Mon 01 Jun 2015, Wed 01 Jul 2015, Sat 01 Aug 2015, Tue 01 Sep 2015, Thu 01 Oct 2015, Sun 01 Nov 2015

echo $rrule->humanReadable(),"\n";
// monthly on the 1st of the month, starting from 01/06/2015, 6 times

Complete documentation and more examples are available in the wiki.

Requirements

  • PHP >= 5.6
  • intl extension is recommended for humanReadable() but not strictly required

Installation

The recommended way is to install the lib through Composer.

Simply run composer require rlanvin/php-rrule for it to be automatically installed and included in your composer.json.

Now you can use the autoloader, and you will have access to the library:

require 'vendor/autoload.php';

Documentation

Complete documentation is available in the wiki.

You will also find useful information in the RFC 5545 section 3.3.10.

Contribution

Feel free to contribute! Just create a new issue or a new pull request.

The coding style is (mostly) PSR-2, but with tabs.

Translation

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.

Note

I started this library because I wasn't happy with the existing implementations in PHP, so I thought it would be a good learning project to port the python-dateutil rrule implementation into PHP.

The Python lib was a bit difficult to understand because the algorithms 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.

The lib differs from the python version in various aspects, notably in the respect of the RFC. This version is a bit strictier and will not accept many 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.