diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index 232841bb6..630515fd0 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -440,6 +440,17 @@ class TimeHelper extends AppHelper { */ function toRSS($dateString, $userOffset = null) { $date = $this->fromString($dateString, $userOffset); + + if(!is_null($userOffset)) { + if($userOffset == 0) { + $timezone = '+0000'; + } else { + $hours = (int) floor(abs($userOffset)); + $minutes = (int) (fmod(abs($userOffset), $hours) * 60); + $timezone = ($userOffset < 0 ? '-' : '+') . str_pad($hours, 2, '0', STR_PAD_LEFT) . str_pad($minutes, 2, '0', STR_PAD_LEFT); + } + return date('D, d M Y H:i:s', $date) . ' ' . $timezone; + } return date("r", $date); } diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index daa77f678..1feae5cea 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -409,6 +409,16 @@ class TimeHelperTest extends CakeTestCase { */ function testToRss() { $this->assertEqual(date('r'), $this->Time->toRss(time())); + + if (!$this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) { + $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'); + foreach($timezones as $timezone) { + $yourTimezone = new DateTimeZone($timezone); + $yourTime = new DateTime('now', $yourTimezone); + $userOffset = $yourTimezone->getOffset($yourTime) / HOUR; + $this->assertEqual($yourTime->format('r'), $this->Time->toRss(time(), $userOffset)); + } + } } /**