Skip to content

Commit 1d53a3d

Browse files
committed
Updating README, LICENSE and comments
1 parent 089dea9 commit 1d53a3d

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
2222

23-
-----------------------
24-
Based on Python's dateutil.
23+
------------------------
24+
Based on python-dateutil. LICENSE:
2525

2626
dateutil - Extensions to the standard Python datetime module.
2727

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# RRULE for PHP
22

3-
Lightweight and fast implementation of recurrence rules for PHP (RFC 5545).
3+
Lightweight and fast implementation of recurrence rules for PHP (RFC 5545), to easily work with recurring dates and events (such as in a calendar).
4+
This library is heavily based on [python-dateutil](https://labix.org/python-dateutil).
45

56
[![Build Status](https://travis-ci.org/rlanvin/php-rrule.svg?branch=master)](https://travis-ci.org/rlanvin/php-rrule)
67

@@ -38,7 +39,7 @@ Complete doc is available in [the wiki](https://github.com/rlanvin/php-rrule/wik
3839
## Installation
3940

4041
This is still a work in progress, use at your own risk!
41-
In particular, HOURLY, MINUTELY and SECONDELY frequencies are not implemented.
42+
In particular, HOURLY, MINUTELY and SECONDLY frequencies are not implemented.
4243

4344
The recommended way is to install the lib [through Composer](http://getcomposer.org/).
4445

@@ -63,20 +64,21 @@ require 'vendor/autoload.php';
6364

6465
### Alternative method
6566

66-
You can download `src/RRule.php` and require it.
67+
Since it's a no-nonsense implementation, there is only one class.
68+
So you can just download `src/RRule.php` and require it.
6769

6870
## Note
6971

7072
I started this library because I wasn't happy with the existing implementations
7173
in PHP. The ones I tested were slow and/or had a very awkward/verbose API that
7274
I didn't like to use. They were also all missing a generator/iterator, which I
7375
think is key. So I thought it would be a good learning project to port the
74-
Python dateutil/rrule.py class into PHP.
76+
python-dateutil rrule implementation into PHP.
7577

76-
The Python lib was a bit difficult to understand at first. The algorithms
77-
used are very smart (and fast), but they not commented and the variables are
78-
very opaque (I'm looking at you `lno1wkst`). I tried to comment and
79-
explain most of the algorithm in this PHP port, so feel free to check the code.
78+
The Python lib was a bit difficult to understand because the algorithms (very smart by the way),
79+
are not commented and the variables are very opaque (I'm looking at
80+
you `lno1wkst`). I tried to comment and explain as much of the algorithm as possible
81+
in this PHP port, so feel free to check the code if you're interested.
8082

8183
The lib differs from the python version in various aspects, notably in the
8284
respect of the RFC. This version is strictier and will not accept many

src/RRule.php

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
<?php
22

33
/**
4-
* Implementation of RRULE as defined by RFC 5545.
5-
*
6-
* Heavily based on dateutil/rrule.py
7-
*
8-
* Some useful terms to understand the algorithms and variables naming:
4+
* Licensed under the MIT license.
95
*
10-
* yearday = day of the year, from 0 to 365 (on leap years) - date('z')
11-
* weekday = day of the week (ISO-8601), from 1 (MO) to 7 (SU) - date('N')
12-
* monthday = day of the month, from 1 to 31
13-
* wkst = week start, the weekday (1 to 7) which is the first day of week.
14-
* Default is Monday (1). In some countries it's Sunday (7).
15-
* weekno = number of the week in the year (ISO-8601)
6+
* For the full copyright and license information, please view the LICENSE file.
167
*
17-
* CAREFUL with that bug: https://bugs.php.net/bug.php?id=62476
8+
* @author Rémi Lanvin <[email protected]>
9+
* @link https://github.com/rlanvin/php-rrule
1810
*/
1911

2012
namespace RRule;
2113

2214
/**
15+
* Check that a variable is not empty. 0 and '0' are considered NOT empty
16+
*
2317
* @return bool
2418
*/
2519
function not_empty($var)
@@ -54,6 +48,7 @@ function pymod($a, $b)
5448
}
5549

5650
/**
51+
* Check is a year is a leap year.
5752
* @return bool
5853
*/
5954
function is_leap_year($year)
@@ -71,7 +66,22 @@ function is_leap_year($year)
7166
}
7267

7368
/**
74-
* Main class.
69+
* Implementation of RRULE as defined by RFC 5545.
70+
* Heavily based on python-dateutil/rrule
71+
*
72+
* Some useful terms to understand the algorithms and variables naming:
73+
*
74+
* yearday = day of the year, from 0 to 365 (on leap years) - date('z')
75+
* weekday = day of the week (ISO-8601), from 1 (MO) to 7 (SU) - date('N')
76+
* monthday = day of the month, from 1 to 31
77+
* wkst = week start, the weekday (1 to 7) which is the first day of week.
78+
* Default is Monday (1). In some countries it's Sunday (7).
79+
* weekno = number of the week in the year (ISO-8601)
80+
*
81+
* CAREFUL with this bug: https://bugs.php.net/bug.php?id=62476
82+
*
83+
* @see https://tools.ietf.org/html/rfc5545
84+
* @see https://labix.org/python-dateutil
7585
*/
7686
class RRule implements \Iterator, \ArrayAccess
7787
{
@@ -950,7 +960,7 @@ protected function buildWeeknoMask($year, $month, $day, & $masks)
950960
}
951961

952962
/**
953-
* This is the main method, where all of the logic happens.
963+
* This is the main method, where all of the magic happens.
954964
*
955965
* This method is a generator that works for PHP 5.3/5.4 (using static variables)
956966
*/
@@ -1125,10 +1135,8 @@ protected function iterate($reset = false)
11251135
// at the same time, we check the end condition and return null if
11261136
// we need to stop
11271137
while ( ($yearday = current($current_set)) !== false ) {
1128-
// $occurrence = date('Y-m-d', mktime(0, 0, 0, 1, ($yearday + 1), $year));
1129-
// echo "\t occurrence (mktime) = ", $occurrence,"\n";
11301138
$occurrence = \DateTime::createFromFormat('Y z', "$year $yearday");
1131-
// echo "\t occurrence (before time) =", $occurrence->format('r'),"\n";
1139+
11321140
while ( ($time = current($timeset)) !== false ) {
11331141
$occurrence->setTime($time[0], $time[1], $time[2]);
11341142
// consider end conditions
@@ -1169,13 +1177,11 @@ protected function iterate($reset = false)
11691177
}
11701178
break;
11711179
case self::WEEKLY:
1172-
// here we take a little shortcut from the Python version, by using date/time methods
1173-
// list($year,$month,$day) = explode('-',date('Y-m-d',strtotime('+'.($this->interval*7).'day', mktime(0,0,0,$month,$day,$year))));
1180+
// here we take a little shortcut from the Python version, by using DateTime
11741181
list($year,$month,$day) = explode('-',(new \DateTime("$year-$month-$day"))->modify('+'.($this->interval*7).'day')->format('Y-n-j'));
11751182
break;
11761183
case self::DAILY:
1177-
// here we take a little shortcut from the Python version, by using date/time methods
1178-
// list($year,$month,$day) = explode('-',date('Y-m-d',strtotime('+'.$this->interval.'day', mktime(0,0,0,$month,$day,$year))));
1184+
// here we take a little shortcut from the Python version, by using DateTime
11791185
list($year,$month,$day) = explode('-',(new \DateTime("$year-$month-$day"))->modify('+'.$this->interval.'day')->format('Y-n-j'));
11801186
break;
11811187
case self::HOURLY:

0 commit comments

Comments
 (0)