1
1
<?php
2
2
3
3
/**
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.
9
5
*
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.
16
7
*
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
18
10
*/
19
11
20
12
namespace RRule ;
21
13
22
14
/**
15
+ * Check that a variable is not empty. 0 and '0' are considered NOT empty
16
+ *
23
17
* @return bool
24
18
*/
25
19
function not_empty ($ var )
@@ -54,6 +48,7 @@ function pymod($a, $b)
54
48
}
55
49
56
50
/**
51
+ * Check is a year is a leap year.
57
52
* @return bool
58
53
*/
59
54
function is_leap_year ($ year )
@@ -71,7 +66,22 @@ function is_leap_year($year)
71
66
}
72
67
73
68
/**
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
75
85
*/
76
86
class RRule implements \Iterator, \ArrayAccess
77
87
{
@@ -950,7 +960,7 @@ protected function buildWeeknoMask($year, $month, $day, & $masks)
950
960
}
951
961
952
962
/**
953
- * This is the main method, where all of the logic happens.
963
+ * This is the main method, where all of the magic happens.
954
964
*
955
965
* This method is a generator that works for PHP 5.3/5.4 (using static variables)
956
966
*/
@@ -1125,10 +1135,8 @@ protected function iterate($reset = false)
1125
1135
// at the same time, we check the end condition and return null if
1126
1136
// we need to stop
1127
1137
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";
1130
1138
$ occurrence = \DateTime::createFromFormat ('Y z ' , "$ year $ yearday " );
1131
- // echo "\t occurrence (before time) =", $occurrence->format('r'),"\n";
1139
+
1132
1140
while ( ($ time = current ($ timeset )) !== false ) {
1133
1141
$ occurrence ->setTime ($ time [0 ], $ time [1 ], $ time [2 ]);
1134
1142
// consider end conditions
@@ -1169,13 +1177,11 @@ protected function iterate($reset = false)
1169
1177
}
1170
1178
break ;
1171
1179
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
1174
1181
list ($ year ,$ month ,$ day ) = explode ('- ' ,(new \DateTime ("$ year- $ month- $ day " ))->modify ('+ ' .($ this ->interval *7 ).'day ' )->format ('Y-n-j ' ));
1175
1182
break ;
1176
1183
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
1179
1185
list ($ year ,$ month ,$ day ) = explode ('- ' ,(new \DateTime ("$ year- $ month- $ day " ))->modify ('+ ' .$ this ->interval .'day ' )->format ('Y-n-j ' ));
1180
1186
break ;
1181
1187
case self ::HOURLY :
0 commit comments