Permalink
Browse files

Using fixed points in time.

This avoids lulz when the United Kingdom changes change to/from DST at
a different time than your local timezone.
  • Loading branch information...
1 parent 494928a commit e8f727fe688855369101a4d5fffcdd7458e0473a @markstory markstory committed Oct 28, 2012
Showing with 13 additions and 12 deletions.
  1. +13 −12 lib/Cake/Test/Case/Utility/CakeTimeTest.php
@@ -474,7 +474,7 @@ public function testToServer() {
date_default_timezone_set('UTC');
- $serverTime = new DateTime('now');
+ $serverTime = new DateTime('2012-12-11 14:15:20');
$timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu');
foreach ($timezones as $timezone) {
@@ -509,17 +509,18 @@ public function testToAtom() {
* @return void
*/
public function testToRss() {
- $this->assertEquals(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->assertEquals($yourTime->format('r'), $this->Time->toRss(time(), $userOffset));
- $this->assertEquals($yourTime->format('r'), $this->Time->toRss(time(), $timezone));
- }
+ $date = '2012-08-12 12:12:45';
+ $time = strtotime($date);
+ $this->assertEquals(date('r', $time), $this->Time->toRss($time));
+
+ $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu');
+ foreach ($timezones as $timezone) {
+ $yourTimezone = new DateTimeZone($timezone);
+ $yourTime = new DateTime($date, $yourTimezone);
+ $userOffset = $yourTimezone->getOffset($yourTime) / HOUR;
+ $time = $yourTime->getTimestamp();
+ $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $userOffset), "Failed on $timezone");
+ $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $timezone), "Failed on $timezone");
}
}

0 comments on commit e8f727f

Please sign in to comment.