Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #182 from jellehenkens/1.3

Fixes #1938 - toRSS() generates the wrong timezone when using userOffset.
  • Loading branch information...
commit 15a174121691b3516b57fafbd591a6d5f02987f0 2 parents 5424475 + da4b75c
@markstory markstory authored
View
11 cake/libs/view/helpers/time.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);
}
View
10 cake/tests/cases/libs/view/helpers/time.test.php
@@ -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));
+ }
+ }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.