From 4442384a6fb006032e2bfb34e095a1f6677263e8 Mon Sep 17 00:00:00 2001 From: gordonzhao Date: Fri, 11 Mar 2016 15:42:34 +1000 Subject: [PATCH] Fix bug with timezone which is not UTC - Add timezone to the Datetime creation - Add timezone to the rfcExample test --- src/RRule.php | 5 +- tests/RRuleTest.php | 156 ++++++++++++++++++++++++++------------------ 2 files changed, 94 insertions(+), 67 deletions(-) diff --git a/src/RRule.php b/src/RRule.php index c28cc3f..d011dd3 100755 --- a/src/RRule.php +++ b/src/RRule.php @@ -1519,7 +1519,8 @@ class RRule implements \Iterator, \ArrayAccess, \Countable if ( ! isset($filtered_set[$tmp]) ) { $occurrence = \DateTime::createFromFormat( 'Y z', - "$year $yearday" + "$year $yearday", + $this->dtstart->getTimezone() ); $occurrence->setTime($time[0], $time[1], $time[2]); $filtered_set[$tmp] = $occurrence; @@ -1554,7 +1555,7 @@ class RRule implements \Iterator, \ArrayAccess, \Countable else { // normal loop, without BYSETPOS 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 ) { $occurrence->setTime($time[0], $time[1], $time[2]); diff --git a/tests/RRuleTest.php b/tests/RRuleTest.php index 3626798..f074131 100755 --- a/tests/RRuleTest.php +++ b/tests/RRuleTest.php @@ -756,17 +756,43 @@ class RRuleTest extends PHPUnit_Framework_TestCase return array( // Daily, for 10 occurrences. array( - array('freq' => 'daily', 'count' => 10, 'dtstart' => '1997-09-02 09:00:00'), - array(date_create('1997-09-02 09:00:00'), - date_create('1997-09-03 09:00:00'), - date_create('1997-09-04 09:00:00'), - date_create('1997-09-05 09:00:00'), - date_create('1997-09-06 09:00:00'), - date_create('1997-09-07 09:00:00'), - date_create('1997-09-08 09:00:00'), - date_create('1997-09-09 09:00:00'), - date_create('1997-09-10 09:00:00'), - date_create('1997-09-11 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',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-04 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-05 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-06 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-07 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-08 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-09 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-10 09:00:00',new DateTimeZone('Australia/Sydney')), + 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 array( @@ -1227,65 +1253,65 @@ class RRuleTest extends PHPUnit_Framework_TestCase ), // Every hour and a half for 4 occurrences. array( - array('freq' => 'MINUTELY', 'interval' => 90, 'count' => 4, 'dtstart' => '1997-09-02 09:00:00'), - array(date_create('1997-09-02 09:00:00'), - date_create('1997-09-02 10:30:00'), - date_create('1997-09-02 12:00:00'), - date_create('1997-09-02 13:30: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',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 10:30:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 12:00:00',new DateTimeZone('Australia/Sydney')), + 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. array( array('freq' => 'MINUTELY', 'interval' => 20, 'count' => 48, 'byhour' => range(9,16), 'byminute' => '0,20,40', - 'dtstart' => '1997-09-02 09:00:00'), array( - date_create('1997-09-02 09:00:00'), - date_create('1997-09-02 09:20:00'), - date_create('1997-09-02 09:40:00'), - date_create('1997-09-02 10:00:00'), - date_create('1997-09-02 10:20:00'), - date_create('1997-09-02 10:40:00'), - date_create('1997-09-02 11:00:00'), - date_create('1997-09-02 11:20:00'), - date_create('1997-09-02 11:40:00'), - date_create('1997-09-02 12:00:00'), - date_create('1997-09-02 12:20:00'), - date_create('1997-09-02 12:40:00'), - date_create('1997-09-02 13:00:00'), - date_create('1997-09-02 13:20:00'), - date_create('1997-09-02 13:40:00'), - date_create('1997-09-02 14:00:00'), - date_create('1997-09-02 14:20:00'), - date_create('1997-09-02 14:40:00'), - date_create('1997-09-02 15:00:00'), - date_create('1997-09-02 15:20:00'), - date_create('1997-09-02 15:40:00'), - date_create('1997-09-02 16:00:00'), - date_create('1997-09-02 16:20:00'), - date_create('1997-09-02 16:40:00'), - date_create('1997-09-03 09:00:00'), - date_create('1997-09-03 09:20:00'), - date_create('1997-09-03 09:40:00'), - date_create('1997-09-03 10:00:00'), - date_create('1997-09-03 10:20:00'), - date_create('1997-09-03 10:40:00'), - date_create('1997-09-03 11:00:00'), - date_create('1997-09-03 11:20:00'), - date_create('1997-09-03 11:40:00'), - date_create('1997-09-03 12:00:00'), - date_create('1997-09-03 12:20:00'), - date_create('1997-09-03 12:40:00'), - date_create('1997-09-03 13:00:00'), - date_create('1997-09-03 13:20:00'), - date_create('1997-09-03 13:40:00'), - date_create('1997-09-03 14:00:00'), - date_create('1997-09-03 14:20:00'), - date_create('1997-09-03 14:40:00'), - date_create('1997-09-03 15:00:00'), - date_create('1997-09-03 15:20:00'), - date_create('1997-09-03 15:40:00'), - date_create('1997-09-03 16:00:00'), - date_create('1997-09-03 16:20:00'), - date_create('1997-09-03 16:40:00')) + 'dtstart' => date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney'))), array( + date_create('1997-09-02 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 09:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 09:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 10:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 10:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 10:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 11:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 11:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 11:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 12:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 12:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 12:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 13:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 13:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 13:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 14:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 14:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 14:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 15:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 15:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 15:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 16:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 16:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-02 16:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 09:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 09:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 09:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 10:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 10:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 10:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 11:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 11:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 11:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 12:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 12:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 12:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 13:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 13:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 13:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 14:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 14:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 14:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 15:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 15:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 15:40:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 16:00:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 16:20:00',new DateTimeZone('Australia/Sydney')), + date_create('1997-09-03 16:40:00',new DateTimeZone('Australia/Sydney'))) ), // An example where the days generated makes a difference because of wkst. array(array('freq' => 'WEEKLY', 'interval' => 2, 'count' => 4,