1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-26 15:54:14 +01:00

Merge pull request #16 from toHero/master

Change values of FREQ when get the RFC string to match the convention
This commit is contained in:
Rémi Lanvin 2016-08-19 14:20:36 +01:00 committed by GitHub
commit ebd3428314
2 changed files with 71 additions and 1 deletions

View File

@ -528,7 +528,7 @@ class RRule implements RRuleInterface
* Magic string converter. * Magic string converter.
* *
* @see RRule::rfcString() * @see RRule::rfcString()
* @return a rfc string * @return string a rfc string
*/ */
public function __toString() public function __toString()
{ {
@ -603,6 +603,12 @@ class RRule implements RRuleInterface
} }
continue; continue;
} }
if ( $key === 'FREQ' && $value && !array_key_exists($value, static::$frequencies) ) {
$frequency_key = array_search($value, static::$frequencies);
if ($frequency_key !== false) {
$value = $frequency_key;
}
}
if ( $value ) { if ( $value ) {
if ( is_array($value) ) { if ( is_array($value) ) {
$value = implode(',',$value); $value = implode(',',$value);

View File

@ -1845,6 +1845,70 @@ class RRuleTest extends PHPUnit_Framework_TestCase
$this->assertEquals($expected_str, $rule->rfcString(false)); $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 // Timezone