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

Fix bug with timezone which is not UTC

- Add timezone to the Datetime creation
  - Add timezone to the rfcExample test
This commit is contained in:
gordonzhao 2016-03-11 15:42:34 +10:00
parent 93f730e990
commit 4442384a6f
2 changed files with 94 additions and 67 deletions

View File

@ -1519,7 +1519,8 @@ class RRule implements \Iterator, \ArrayAccess, \Countable
if ( ! isset($filtered_set[$tmp]) ) { if ( ! isset($filtered_set[$tmp]) ) {
$occurrence = \DateTime::createFromFormat( $occurrence = \DateTime::createFromFormat(
'Y z', 'Y z',
"$year $yearday" "$year $yearday",
$this->dtstart->getTimezone()
); );
$occurrence->setTime($time[0], $time[1], $time[2]); $occurrence->setTime($time[0], $time[1], $time[2]);
$filtered_set[$tmp] = $occurrence; $filtered_set[$tmp] = $occurrence;
@ -1554,7 +1555,7 @@ class RRule implements \Iterator, \ArrayAccess, \Countable
else { else {
// normal loop, without BYSETPOS // normal loop, without BYSETPOS
while ( ($yearday = current($dayset)) !== false ) { while ( ($yearday = current($dayset)) !== false ) {
$occurrence = \DateTime::createFromFormat('Y z', "$year $yearday"); $occurrence = \DateTime::createFromFormat('Y z', "$year $yearday",$this->dtstart->getTimezone());
while ( ($time = current($timeset)) !== false ) { while ( ($time = current($timeset)) !== false ) {
$occurrence->setTime($time[0], $time[1], $time[2]); $occurrence->setTime($time[0], $time[1], $time[2]);

View File

@ -756,17 +756,43 @@ class RRuleTest extends PHPUnit_Framework_TestCase
return array( return array(
// Daily, for 10 occurrences. // Daily, for 10 occurrences.
array( array(
array('freq' => 'daily', 'count' => 10, 'dtstart' => '1997-09-02 09:00:00'), array('freq' => 'daily', 'count' => 10, 'dtstart' => date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney'))),
array(date_create('1997-09-02 09:00:00'), array(date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 09:00:00'), date_create('1997-09-03 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-04 09:00:00'), date_create('1997-09-04 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-05 09:00:00'), date_create('1997-09-05 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-06 09:00:00'), date_create('1997-09-06 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-07 09:00:00'), date_create('1997-09-07 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-08 09:00:00'), date_create('1997-09-08 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-09 09:00:00'), date_create('1997-09-09 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-10 09:00:00'), date_create('1997-09-10 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-11 09:00:00')) date_create('1997-09-11 09:00:00',new DateTimeZone('Australia/Sydney')))
),
array(
array('freq' => 'daily', 'count' => 10, 'dtstart' => date_create('2016-10-02 09:00:00',new DateTimeZone('Australia/Sydney'))),
array(date_create('2016-10-02 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-03 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-04 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-05 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-06 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-07 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-08 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-09 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-10 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-10-11 09:00:00',new DateTimeZone('Australia/Sydney')))
),
array(
array('freq' => 'daily', 'count' => 10, 'dtstart' => date_create('2016-04-02 09:00:00',new DateTimeZone('Australia/Sydney'))),
array(date_create('2016-04-02 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-03 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-04 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-05 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-06 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-07 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-08 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-09 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-10 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('2016-04-11 09:00:00',new DateTimeZone('Australia/Sydney')))
), ),
// Daily until December 24, 1997 // Daily until December 24, 1997
array( array(
@ -1227,65 +1253,65 @@ class RRuleTest extends PHPUnit_Framework_TestCase
), ),
// Every hour and a half for 4 occurrences. // Every hour and a half for 4 occurrences.
array( array(
array('freq' => 'MINUTELY', 'interval' => 90, 'count' => 4, 'dtstart' => '1997-09-02 09:00:00'), array('freq' => 'MINUTELY', 'interval' => 90, 'count' => 4, 'dtstart' => date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney'))),
array(date_create('1997-09-02 09:00:00'), array(date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 10:30:00'), date_create('1997-09-02 10:30:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 12:00:00'), date_create('1997-09-02 12:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 13:30:00')) date_create('1997-09-02 13:30:00',new DateTimeZone('Australia/Sydney')))
), ),
// Every 20 minutes from 9:00 AM to 4:40 PM for two days. // Every 20 minutes from 9:00 AM to 4:40 PM for two days.
array( array(
array('freq' => 'MINUTELY', 'interval' => 20, 'count' => 48, array('freq' => 'MINUTELY', 'interval' => 20, 'count' => 48,
'byhour' => range(9,16), 'byminute' => '0,20,40', 'byhour' => range(9,16), 'byminute' => '0,20,40',
'dtstart' => '1997-09-02 09:00:00'), array( 'dtstart' => date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney'))), array(
date_create('1997-09-02 09:00:00'), date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 09:20:00'), date_create('1997-09-02 09:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 09:40:00'), date_create('1997-09-02 09:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 10:00:00'), date_create('1997-09-02 10:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 10:20:00'), date_create('1997-09-02 10:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 10:40:00'), date_create('1997-09-02 10:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 11:00:00'), date_create('1997-09-02 11:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 11:20:00'), date_create('1997-09-02 11:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 11:40:00'), date_create('1997-09-02 11:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 12:00:00'), date_create('1997-09-02 12:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 12:20:00'), date_create('1997-09-02 12:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 12:40:00'), date_create('1997-09-02 12:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 13:00:00'), date_create('1997-09-02 13:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 13:20:00'), date_create('1997-09-02 13:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 13:40:00'), date_create('1997-09-02 13:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 14:00:00'), date_create('1997-09-02 14:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 14:20:00'), date_create('1997-09-02 14:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 14:40:00'), date_create('1997-09-02 14:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 15:00:00'), date_create('1997-09-02 15:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 15:20:00'), date_create('1997-09-02 15:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 15:40:00'), date_create('1997-09-02 15:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 16:00:00'), date_create('1997-09-02 16:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 16:20:00'), date_create('1997-09-02 16:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-02 16:40:00'), date_create('1997-09-02 16:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 09:00:00'), date_create('1997-09-03 09:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 09:20:00'), date_create('1997-09-03 09:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 09:40:00'), date_create('1997-09-03 09:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 10:00:00'), date_create('1997-09-03 10:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 10:20:00'), date_create('1997-09-03 10:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 10:40:00'), date_create('1997-09-03 10:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 11:00:00'), date_create('1997-09-03 11:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 11:20:00'), date_create('1997-09-03 11:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 11:40:00'), date_create('1997-09-03 11:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 12:00:00'), date_create('1997-09-03 12:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 12:20:00'), date_create('1997-09-03 12:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 12:40:00'), date_create('1997-09-03 12:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 13:00:00'), date_create('1997-09-03 13:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 13:20:00'), date_create('1997-09-03 13:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 13:40:00'), date_create('1997-09-03 13:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 14:00:00'), date_create('1997-09-03 14:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 14:20:00'), date_create('1997-09-03 14:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 14:40:00'), date_create('1997-09-03 14:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 15:00:00'), date_create('1997-09-03 15:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 15:20:00'), date_create('1997-09-03 15:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 15:40:00'), date_create('1997-09-03 15:40:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 16:00:00'), date_create('1997-09-03 16:00:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 16:20:00'), date_create('1997-09-03 16:20:00',new DateTimeZone('Australia/Sydney')),
date_create('1997-09-03 16:40:00')) date_create('1997-09-03 16:40:00',new DateTimeZone('Australia/Sydney')))
), ),
// An example where the days generated makes a difference because of wkst. // An example where the days generated makes a difference because of wkst.
array(array('freq' => 'WEEKLY', 'interval' => 2, 'count' => 4, array(array('freq' => 'WEEKLY', 'interval' => 2, 'count' => 4,