Permalink
Browse files

Fixing issue where the time helper sets the wrong timezone part in RS…

…S dates
  • Loading branch information...
1 parent aee650d commit da4b75c99383957b3974b019a28dd1777765fe6d Jelle Henkens committed Aug 26, 2011
Showing with 21 additions and 0 deletions.
  1. +11 −0 cake/libs/view/helpers/time.php
  2. +10 −0 cake/tests/cases/libs/view/helpers/time.test.php
@@ -440,6 +440,17 @@ function toAtom($dateString, $userOffset = null) {
*/
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);
}
@@ -409,6 +409,16 @@ function testToAtom() {
*/
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));
+ }
+ }
}
/**

0 comments on commit da4b75c

Please sign in to comment.