mirror of
https://github.com/rlanvin/php-rrule.git
synced 2025-02-20 09:54:16 +01:00
Remove unused code and fix outdated comments
This commit is contained in:
parent
e3d5f8c629
commit
deed61e0c2
@ -7,6 +7,10 @@
|
||||
- Persian (Farsi) translation [#72](https://github.com/rlanvin/php-rrule/pull/72)
|
||||
- Support for Windows timezone [#69](https://github.com/rlanvin/php-rrule/issues/69)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed RRule::createFromRfcString not detecting RSet properly if the rule was lowercase
|
||||
|
||||
## [2.1.0] - 2019-05-30
|
||||
|
||||
### Fixed
|
||||
|
@ -19,7 +19,7 @@ $rrule = new RRule([
|
||||
'COUNT' => 6
|
||||
]);
|
||||
|
||||
foreach ( $rrule as $occurrence ) {
|
||||
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
|
||||
|
@ -22,6 +22,7 @@
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8|^5.5|^6.5"
|
||||
"phpunit/phpunit": "^4.8|^5.5|^6.5",
|
||||
"phpmd/phpmd" : "@stable"
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +680,7 @@ class RRule implements RRuleInterface
|
||||
|
||||
if (! $force_rset) {
|
||||
// try to detect if we have a RRULE or a set
|
||||
$uppercased_string = strtoupper($string);
|
||||
$string = strtoupper($string);
|
||||
$nb_rrule = substr_count($string, 'RRULE');
|
||||
if ($nb_rrule == 0) {
|
||||
$class = '\RRule\RRule';
|
||||
@ -834,7 +834,7 @@ class RRule implements RRuleInterface
|
||||
|
||||
// so now we have exhausted all the BYXXX rules (exept bysetpos),
|
||||
// we still need to consider frequency and interval
|
||||
list ($start_year, $start_month, $start_day) = explode('-',$this->dtstart->format('Y-m-d'));
|
||||
list($start_year, $start_month) = explode('-',$this->dtstart->format('Y-m'));
|
||||
switch ($this->freq) {
|
||||
case self::YEARLY:
|
||||
if (($year - $start_year) % $this->interval !== 0) {
|
||||
@ -920,58 +920,6 @@ class RRule implements RRuleInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Iterator interface
|
||||
// Note: if cache is complete, we could probably avoid completely calling iterate()
|
||||
// and instead iterate directly on the $this->cache array
|
||||
|
||||
// /** @internal */
|
||||
// protected $current = 0;
|
||||
// /** @internal */
|
||||
// protected $key = 0;
|
||||
|
||||
// /**
|
||||
// * @internal
|
||||
// */
|
||||
// public function rewind()
|
||||
// {
|
||||
// $this->current = $this->iterate(true);
|
||||
// $this->key = 0;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @internal
|
||||
// */
|
||||
// public function current()
|
||||
// {
|
||||
// return $this->current;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @internal
|
||||
// */
|
||||
// public function key()
|
||||
// {
|
||||
// return $this->key;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @internal
|
||||
// */
|
||||
// public function next()
|
||||
// {
|
||||
// $this->current = $this->iterate();
|
||||
// $this->key += 1;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @internal
|
||||
// */
|
||||
// public function valid()
|
||||
// {
|
||||
// return $this->current !== null;
|
||||
// }
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ArrayAccess interface
|
||||
|
||||
@ -1115,12 +1063,12 @@ class RRule implements RRuleInterface
|
||||
* the first Sunday of Jan 1998 is yearday 3 (counting from 0) and the
|
||||
* last Sunday of Jan 1998 is yearday 24 (counting from 0).
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $year (not used)
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
* @param int $day (not used)
|
||||
* @param array $masks
|
||||
*
|
||||
* @return null (modifies $mask parameter)
|
||||
* @return null (modifies $masks parameter)
|
||||
*/
|
||||
protected function buildNthWeekdayMask($year, $month, $day, array & $masks)
|
||||
{
|
||||
@ -1182,11 +1130,11 @@ class RRule implements RRuleInterface
|
||||
* algorithm is quite long.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
* @param int $month (not used)
|
||||
* @param int $day (not used)
|
||||
* @param array $masks
|
||||
*
|
||||
* @return null (modifies $mask)
|
||||
* @return null (modifies $masks)
|
||||
*/
|
||||
protected function buildWeeknoMask($year, $month, $day, array & $masks)
|
||||
{
|
||||
@ -1344,9 +1292,8 @@ class RRule implements RRuleInterface
|
||||
/**
|
||||
* This is the main method, where all of the magic happens.
|
||||
*
|
||||
* This method is a generator that works for PHP 5.3/5.4 (using static variables)
|
||||
*
|
||||
* The main idea is: a brute force made fast by not relying on date() functions
|
||||
* The main idea is: a brute force loop testing all the dates, made fast by
|
||||
* not relying on date() functions
|
||||
*
|
||||
* There is one big loop that examines every interval of the given frequency
|
||||
* (so every day, every week, every month or every year), constructs an
|
||||
@ -1386,7 +1333,6 @@ class RRule implements RRuleInterface
|
||||
* (I don't know yet which one first), and then if that results in a change of
|
||||
* month, attempt to jump to the next BYMONTH, and so on.
|
||||
*
|
||||
* @param $reset (bool) Whether to restart the iteration, or keep going
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getIterator()
|
||||
@ -1476,7 +1422,6 @@ class RRule implements RRuleInterface
|
||||
if ($masks['year'] != $year) {
|
||||
$masks['leap_year'] = is_leap_year($year);
|
||||
$masks['year_len'] = 365 + (int) $masks['leap_year'];
|
||||
$masks['next_year_len'] = 365 + is_leap_year($year + 1);
|
||||
$masks['weekday_of_1st_yearday'] = date_create($year."-01-01 00:00:00")->format('N');
|
||||
$masks['yearday_to_weekday'] = array_slice(self::$WEEKDAY_MASK, $masks['weekday_of_1st_yearday']-1);
|
||||
if ($masks['leap_year']) {
|
||||
@ -1507,7 +1452,6 @@ class RRule implements RRuleInterface
|
||||
$dayset = $this->getDaySet($year, $month, $day, $masks);
|
||||
|
||||
$filtered_set = array();
|
||||
|
||||
// filter out the days based on the BYXXX rules
|
||||
foreach ($dayset as $yearday) {
|
||||
if ($this->bymonth && ! in_array($masks['yearday_to_month'][$yearday], $this->bymonth)) {
|
||||
@ -1519,15 +1463,8 @@ class RRule implements RRuleInterface
|
||||
}
|
||||
|
||||
if ($this->byyearday) {
|
||||
if ($yearday < $masks['year_len']) {
|
||||
if (! in_array($yearday + 1, $this->byyearday) && ! in_array(- $masks['year_len'] + $yearday,$this->byyearday)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else { // if ( ($yearday >= $masks['year_len']
|
||||
if (! in_array($yearday + 1 - $masks['year_len'], $this->byyearday) && ! in_array(- $masks['next_year_len'] + $yearday - $mask['year_len'], $this->byyearday)) {
|
||||
continue;
|
||||
}
|
||||
if (! in_array($yearday + 1, $this->byyearday) && ! in_array(- $masks['year_len'] + $yearday,$this->byyearday)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,14 +151,26 @@ class RRuleTest extends TestCase
|
||||
date_create('1998-01-01'),date_create('1998-02-03'),date_create('1998-03-03'))),
|
||||
array(array('BYMONTHDAY' => array(1,3), 'BYDAY' => array('TU','TH'), 'BYMONTH' => array(1,3)), array(
|
||||
date_create('1998-01-01'),date_create('1998-03-03'),date_create('2001-03-01'))),
|
||||
array(array('BYYEARDAY' => array(1,100,200,365), 'COUNT' => 4), array(
|
||||
'byyearday positive' => array(array('BYYEARDAY' => array(1,100,200,365), 'COUNT' => 4), array(
|
||||
date_create('1997-12-31'),date_create('1998-01-01'),date_create('1998-04-10'), date_create('1998-07-19'))),
|
||||
array(array('BYYEARDAY' => array(-365, -266, -166, -1), 'COUNT' => 4), array(
|
||||
'byyearday negative' => array(array('BYYEARDAY' => array(-365, -266, -166, -1), 'COUNT' => 4), array(
|
||||
date_create('1997-12-31'),date_create('1998-01-01'),date_create('1998-04-10'), date_create('1998-07-19'))),
|
||||
array(array('BYYEARDAY' => array(1,100,200,365), 'BYMONTH' => array(4,7), 'COUNT' => 4), array(
|
||||
'byyearday positive + bymonth' => array(array('BYYEARDAY' => array(1,100,200,365), 'BYMONTH' => array(4,7), 'COUNT' => 4), array(
|
||||
date_create('1998-04-10'),date_create('1998-07-19'),date_create('1999-04-10'), date_create('1999-07-19'))),
|
||||
array(array('BYYEARDAY' => array(-365, -266, -166, -1), 'BYMONTH' => array(4,7), 'COUNT' => 4), array(
|
||||
'byyearday negative + bymonth' => array(array('BYYEARDAY' => array(-365, -266, -166, -1), 'BYMONTH' => array(4,7), 'COUNT' => 4), array(
|
||||
date_create('1998-04-10'),date_create('1998-07-19'),date_create('1999-04-10'), date_create('1999-07-19'))),
|
||||
'byyearday, 29 February' => [
|
||||
['BYYEARDAY' => '60'],
|
||||
[date_create('1998-03-01'), date_create('1999-03-01'), date_create('2000-02-29')]
|
||||
],
|
||||
'byyearday, 366th day' => [
|
||||
['BYYEARDAY' => '366'],
|
||||
[date_create('2000-12-31'), date_create('2004-12-31'), date_create('2008-12-31')]
|
||||
],
|
||||
'byyearday, -366th day' => [
|
||||
['BYYEARDAY' => '-366'],
|
||||
[date_create('2000-01-01'), date_create('2004-01-01'), date_create('2008-01-01')]
|
||||
],
|
||||
array(array('BYWEEKNO' => 20),array(
|
||||
date_create('1998-05-11'),date_create('1998-05-12'),date_create('1998-05-13'))),
|
||||
// That's a nice one. The first days of week number one may be in the last year.
|
||||
@ -551,6 +563,18 @@ class RRuleTest extends TestCase
|
||||
date_create('1998-04-10 01:00'),
|
||||
date_create('1998-04-10 02:00'),
|
||||
date_create('1998-04-10 03:00'))),
|
||||
'byyearday, 29 February' => [
|
||||
['BYYEARDAY' => '60'],
|
||||
[date_create('1998-03-01 00:00'), date_create('1998-03-01 01:00'), date_create('1998-03-01 02:00')]
|
||||
],
|
||||
'byyearday, 366th day' => [
|
||||
['BYYEARDAY' => '366'],
|
||||
[date_create('2000-12-31 00:00'), date_create('2000-12-31 01:00'), date_create('2000-12-31 02:00')]
|
||||
],
|
||||
'byyearday, -366th day' => [
|
||||
['BYYEARDAY' => '-366'],
|
||||
[date_create('2000-01-01 00:00'), date_create('2000-01-01 01:00'), date_create('2000-01-01 02:00')]
|
||||
],
|
||||
array(array('byhour'=>'6, 18'), array(
|
||||
date_create('1997-09-02 18:00'),
|
||||
date_create('1997-09-03 06:00'),
|
||||
@ -2369,7 +2393,15 @@ class RRuleTest extends TestCase
|
||||
array(
|
||||
"DTSTART;TZID=America/New_York:19970901T090000\nRRULE:FREQ=DAILY\nEXRULE:FREQ=YEARLY\nEXDATE;TZID=America/New_York:19970902T090000",
|
||||
'\RRule\RSet'
|
||||
)
|
||||
),
|
||||
'lowercase rrule' => [
|
||||
"rrule:freq=yearly;count=3",
|
||||
"\RRule\RRule"
|
||||
],
|
||||
'lowercase rset with 2 rrules' => [
|
||||
"rrule:freq=yearly;count=3\nrrule:freq=monthly",
|
||||
"\RRule\RSet"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -9,23 +9,24 @@ class RfcParserTest extends TestCase
|
||||
{
|
||||
public function rfcLines()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
// line, default, expected
|
||||
return [
|
||||
[
|
||||
'RDATE;TZID=America/New_York:19970714T083000',
|
||||
array(),
|
||||
array('name' => 'RDATE', 'params' => array('TZID' => 'America/New_York'), 'value' => '19970714T083000')
|
||||
),
|
||||
array(
|
||||
[],
|
||||
['name' => 'RDATE', 'params' => ['TZID' => 'America/New_York'], 'value' => '19970714T083000']
|
||||
],
|
||||
[
|
||||
'RRULE:FREQ=YEARLY;UNTIL=20170202',
|
||||
array(),
|
||||
array('name' => 'RRULE', 'params' => array(), 'value' => 'FREQ=YEARLY;UNTIL=20170202')
|
||||
),
|
||||
array(
|
||||
[],
|
||||
['name' => 'RRULE', 'params' => [], 'value' => 'FREQ=YEARLY;UNTIL=20170202']
|
||||
],
|
||||
[
|
||||
'DTSTART=20160202T000000Z;FREQ=DAILY;UNTIL=20160205T000000Z',
|
||||
array('name' => 'RRULE'),
|
||||
array('name' => 'RRULE', 'params' => array(), 'value' => 'DTSTART=20160202T000000Z;FREQ=DAILY;UNTIL=20160205T000000Z')
|
||||
)
|
||||
);
|
||||
['name' => 'RRULE'],
|
||||
['name' => 'RRULE', 'params' => [], 'value' => 'DTSTART=20160202T000000Z;FREQ=DAILY;UNTIL=20160205T000000Z']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user