From 8fbc51e499bb032df0d11863cbf945dd461d284d Mon Sep 17 00:00:00 2001 From: Antoine Chabert Date: Wed, 17 Aug 2016 17:14:35 +0200 Subject: [PATCH 1/2] Change values of FREQ when get the RFC string to match the convention --- src/RRule.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/RRule.php b/src/RRule.php index bd988dd..33b051e 100755 --- a/src/RRule.php +++ b/src/RRule.php @@ -528,7 +528,7 @@ class RRule implements RRuleInterface * Magic string converter. * * @see RRule::rfcString() - * @return a rfc string + * @return string a rfc string */ public function __toString() { @@ -603,6 +603,12 @@ class RRule implements RRuleInterface } continue; } + if ( $key === 'FREQ' && $value && !array_key_exists($value, static::$frequencies) ) { + $frequencyKey = array_search($value, static::$frequencies); + if ($frequencyKey !== false) { + $value = $frequencyKey; + } + } if ( $value ) { if ( is_array($value) ) { $value = implode(',',$value); From d7acacad6a381a60cfd2f90616ad460dbc815a33 Mon Sep 17 00:00:00 2001 From: Antoine Chabert Date: Wed, 17 Aug 2016 23:14:38 +0200 Subject: [PATCH 2/2] Add tests to reveal the to RFC string error - Fix typo in variable of rfcString function of RRule --- src/RRule.php | 6 ++--- tests/RRuleTest.php | 64 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/RRule.php b/src/RRule.php index 33b051e..5e3aaea 100755 --- a/src/RRule.php +++ b/src/RRule.php @@ -604,9 +604,9 @@ class RRule implements RRuleInterface continue; } if ( $key === 'FREQ' && $value && !array_key_exists($value, static::$frequencies) ) { - $frequencyKey = array_search($value, static::$frequencies); - if ($frequencyKey !== false) { - $value = $frequencyKey; + $frequency_key = array_search($value, static::$frequencies); + if ($frequency_key !== false) { + $value = $frequency_key; } } if ( $value ) { diff --git a/tests/RRuleTest.php b/tests/RRuleTest.php index 34a2030..856f76a 100755 --- a/tests/RRuleTest.php +++ b/tests/RRuleTest.php @@ -1845,6 +1845,70 @@ class RRuleTest extends PHPUnit_Framework_TestCase $this->assertEquals($expected_str, $rule->rfcString(false)); } + public function rfcStringsGenerated() + { + return array( + array( + array( + 'FREQ' => RRule::YEARLY, + 'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney')) + ), + "DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=YEARLY" + ), + array( + array( + 'FREQ' => RRule::MONTHLY, + 'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney')) + ), + "DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=MONTHLY" + ), + array( + array( + 'FREQ' => RRule::WEEKLY, + 'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney')) + ), + "DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=WEEKLY" + ), + array( + array( + 'FREQ' => RRule::DAILY, + 'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney')) + ), + "DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=DAILY" + ), + array( + array( + 'FREQ' => RRule::HOURLY, + 'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney')) + ), + "DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=HOURLY" + ), + array( + array( + 'FREQ' => RRule::MINUTELY, + 'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney')) + ), + "DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=MINUTELY" + ), + array( + array( + 'FREQ' => RRule::SECONDLY, + 'DTSTART' => date_create('2015-07-01 09:00:00', new DateTimeZone('Australia/Sydney')) + ), + "DTSTART;TZID=Australia/Sydney:20150701T090000\nRRULE:FREQ=SECONDLY" + ), + ); + } + + /** + * @dataProvider rfcStringsGenerated + */ + public function testRfcStringsGenerated($params, $expected_str) + { + $rule = new RRule($params); + $this->assertEquals($expected_str, $rule->rfcString()); + } + /////////////////////////////////////////////////////////////////////////////// // Timezone