mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixing issue where the time helper sets the wrong timezone part in RSS dates
This commit is contained in:
parent
aee650defb
commit
da4b75c993
2 changed files with 21 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue