Browse Source

CakeTime functions can now use timezone string or DateTimeZone object for user offsets. (Passing numeric offsets has been kept for BC)

ADmad 14 years ago
parent
commit
d34f0c2bd8

+ 12 - 0
lib/Cake/Test/Case/Utility/CakeTimeTest.php

@@ -418,6 +418,7 @@ class CakeTimeTest extends CakeTestCase {
 				$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));
 			}
 		}
 	}
@@ -623,6 +624,12 @@ class CakeTimeTest extends CakeTestCase {
 		$expected = time();
 		$result = $this->Time->fromString(time(), $yourTimezone);
 		$this->assertEquals($expected, $result);
+
+		$result = $this->Time->fromString(time(), $timezoneServer->getName());
+		$this->assertEquals($expected, $result);
+
+		$result = $this->Time->fromString(time(), $timezoneServer);
+		$this->assertEquals($expected, $result);
 	}
 
 /**
@@ -645,6 +652,11 @@ class CakeTimeTest extends CakeTestCase {
 		$result = $this->Time->fromString('+1 hour', $timezone);
 		$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
 		$this->assertEquals($expected, $result);
+
+		$timezone = date_default_timezone_get();
+		$result = $this->Time->fromString('+1 hour', $timezone);
+		$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
+		$this->assertEquals($expected, $result);
 	}
 
 /**

+ 90 - 69
lib/Cake/Utility/CakeTime.php

@@ -36,7 +36,7 @@ class CakeTime {
  * `strftime` (http://php.net/manual/en/function.strftime.php)
  *
  * @var string
- * @see TimeHelper::format()
+ * @see CakeTime::format()
  */
 	public static $niceFormat = '%a, %b %eS %Y, %H:%M';
 
@@ -195,15 +195,23 @@ class CakeTime {
  * Converts given time (in server's time zone) to user's local time, given his/her offset from GMT.
  *
  * @param string $serverTime UNIX timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return integer UNIX timestamp
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function convert($serverTime, $userOffset) {
+	public static function convert($serverTime, $timezone) {
 		$serverOffset = self::serverOffset();
 		$gmtTime = $serverTime - $serverOffset;
-		$userTime = $gmtTime + $userOffset * (60 * 60);
-		return $userTime;
+		if (is_numeric($timezone)) {
+			$userOffset = $timezone * (60 * 60);
+		} else {
+			if (!is_object($timezone)) {
+				$timezone = new DateTimeZone($timezone);
+			}
+			$userOffset = $timezone->getOffset(new DateTime('@' . $gmtTime));
+		}
+		$userTime = $gmtTime + $userOffset;
+		return (int)$userTime;
 	}
 
 /**
@@ -220,21 +228,23 @@ class CakeTime {
  * Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
  *
  * @param string $dateString Datetime string
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Parsed timestamp
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function fromString($dateString, $userOffset = null) {
+	public static function fromString($dateString, $timezone = null) {
 		if (empty($dateString)) {
 			return false;
 		}
+
 		if (is_integer($dateString) || is_numeric($dateString)) {
 			$date = intval($dateString);
 		} else {
 			$date = strtotime($dateString);
 		}
-		if ($userOffset !== null) {
-			return self::convert($date, $userOffset);
+
+		if ($timezone !== null) {
+			return self::convert($date, $timezone);
 		}
 		if ($date === -1) {
 			return false;
@@ -249,14 +259,14 @@ class CakeTime {
  * using locale strings.
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @param string $format The format to use. If null, `TimeHelper::$niceFormat` is used
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function nice($dateString = null, $userOffset = null, $format = null) {
+	public static function nice($dateString = null, $timezone = null, $format = null) {
 		if ($dateString != null) {
-			$date = self::fromString($dateString, $userOffset);
+			$date = self::fromString($dateString, $timezone);
 		} else {
 			$date = time();
 		}
@@ -276,18 +286,18 @@ class CakeTime {
  * include mention of the year.
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Described, relative date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function niceShort($dateString = null, $userOffset = null) {
-		$date = $dateString ? self::fromString($dateString, $userOffset) : time();
+	public static function niceShort($dateString = null, $timezone = null) {
+		$date = $dateString ? self::fromString($dateString, $timezone) : time();
 
 		$y = self::isThisYear($date) ? '' : ' %Y';
 
-		if (self::isToday($dateString, $userOffset)) {
+		if (self::isToday($dateString, $timezone)) {
 			$ret = __d('cake', 'Today, %s', self::_strftime("%H:%M", $date));
-		} elseif (self::wasYesterday($dateString, $userOffset)) {
+		} elseif (self::wasYesterday($dateString, $timezone)) {
 			$ret = __d('cake', 'Yesterday, %s', self::_strftime("%H:%M", $date));
 		} else {
 			$format = self::convertSpecifiers("%b %eS{$y}, %H:%M", $date);
@@ -303,13 +313,13 @@ class CakeTime {
  * @param string $begin Datetime string or Unix timestamp
  * @param string $end Datetime string or Unix timestamp
  * @param string $fieldName Name of database field to compare with
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Partial SQL string.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function daysAsSql($begin, $end, $fieldName, $userOffset = null) {
-		$begin = self::fromString($begin, $userOffset);
-		$end = self::fromString($end, $userOffset);
+	public static function daysAsSql($begin, $end, $fieldName, $timezone = null) {
+		$begin = self::fromString($begin, $timezone);
+		$end = self::fromString($end, $timezone);
 		$begin = date('Y-m-d', $begin) . ' 00:00:00';
 		$end = date('Y-m-d', $end) . ' 23:59:59';
 
@@ -322,11 +332,11 @@ class CakeTime {
  *
  * @param string $dateString Datetime string or Unix timestamp
  * @param string $fieldName Name of database field to compare with
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Partial SQL string.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function dayAsSql($dateString, $fieldName, $userOffset = null) {
+	public static function dayAsSql($dateString, $fieldName, $timezone = null) {
 		return self::daysAsSql($dateString, $dateString, $fieldName);
 	}
 
@@ -334,12 +344,12 @@ class CakeTime {
  * Returns true if given datetime string is today.
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return boolean True if datetime string is today
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public static function isToday($dateString, $userOffset = null) {
-		$date = self::fromString($dateString, $userOffset);
+	public static function isToday($dateString, $timezone = null) {
+		$date = self::fromString($dateString, $timezone);
 		return date('Y-m-d', $date) == date('Y-m-d', time());
 	}
 
@@ -347,23 +357,23 @@ class CakeTime {
  * Returns true if given datetime string is within this week.
  *
  * @param string $dateString
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return boolean True if datetime string is within current week
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public static function isThisWeek($dateString, $userOffset = null) {
-		$date = self::fromString($dateString, $userOffset);
+	public static function isThisWeek($dateString, $timezone = null) {
+		$date = self::fromString($dateString, $timezone);
 		return date('W o', $date) == date('W o', time());
 	}
 
 /**
  * Returns true if given datetime string is within this month
  * @param string $dateString
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return boolean True if datetime string is within current month
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public static function isThisMonth($dateString, $userOffset = null) {
+	public static function isThisMonth($dateString, $timezone = null) {
 		$date = self::fromString($dateString);
 		return date('m Y', $date) == date('m Y', time());
 	}
@@ -372,12 +382,12 @@ class CakeTime {
  * Returns true if given datetime string is within current year.
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return boolean True if datetime string is within current year
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public static function isThisYear($dateString, $userOffset = null) {
-		$date = self::fromString($dateString, $userOffset);
+	public static function isThisYear($dateString, $timezone = null) {
+		$date = self::fromString($dateString, $timezone);
 		return date('Y', $date) == date('Y', time());
 	}
 
@@ -385,13 +395,13 @@ class CakeTime {
  * Returns true if given datetime string was yesterday.
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return boolean True if datetime string was yesterday
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  *
  */
-	public static function wasYesterday($dateString, $userOffset = null) {
-		$date = self::fromString($dateString, $userOffset);
+	public static function wasYesterday($dateString, $timezone = null) {
+		$date = self::fromString($dateString, $timezone);
 		return date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
 	}
 
@@ -399,12 +409,12 @@ class CakeTime {
  * Returns true if given datetime string is tomorrow.
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return boolean True if datetime string was yesterday
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public static function isTomorrow($dateString, $userOffset = null) {
-		$date = self::fromString($dateString, $userOffset);
+	public static function isTomorrow($dateString, $timezone = null) {
+		$date = self::fromString($dateString, $timezone);
 		return date('Y-m-d', $date) == date('Y-m-d', strtotime('tomorrow'));
 	}
 
@@ -449,24 +459,24 @@ class CakeTime {
  * Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
  *
  * @param string $dateString Datetime string to be represented as a Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return integer Unix timestamp
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function toUnix($dateString, $userOffset = null) {
-		return self::fromString($dateString, $userOffset);
+	public static function toUnix($dateString, $timezone = null) {
+		return self::fromString($dateString, $timezone);
 	}
 
 /**
  * Returns a date formatted for Atom RSS feeds.
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function toAtom($dateString, $userOffset = null) {
-		$date = self::fromString($dateString, $userOffset);
+	public static function toAtom($dateString, $timezone = null) {
+		$date = self::fromString($dateString, $timezone);
 		return date('Y-m-d\TH:i:s\Z', $date);
 	}
 
@@ -474,14 +484,24 @@ class CakeTime {
  * Formats date for RSS feeds
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function toRSS($dateString, $userOffset = null) {
-		$date = self::fromString($dateString, $userOffset);
+	public static function toRSS($dateString, $timezone = null) {
+		$date = self::fromString($dateString, $timezone);
 
-		if (!is_null($userOffset)) {
+		if (!is_null($timezone)) {
+			if (is_numeric($timezone)) {
+				$userOffset = $timezone;
+			} else {
+				if (!is_object($timezone)) {
+					$timezone = new DateTimeZone($timezone);
+				}
+				$currentDate = new DateTime('@' . $date);
+				$currentDate->setTimezone($timezone);
+				$userOffset = $timezone->getOffset($currentDate) / 60 / 60;
+			}
 			if ($userOffset == 0) {
 				$timezone = '+0000';
 			} else {
@@ -520,15 +540,16 @@ class CakeTime {
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 	public static function timeAgoInWords($dateTime, $options = array()) {
-		$userOffset = null;
-		if (is_array($options) && isset($options['userOffset'])) {
-			$userOffset = $options['userOffset'];
-		}
-		$now = time();
-		if (!is_null($userOffset)) {
-			$now = self::convert(time(), $userOffset);
+		$timezone = null;
+		if (is_array($options)) {
+			if (isset($options['userOffset'])) {
+				$timezone = $options['userOffset'];
+			} elseif (isset($options['timezone'])) {
+				$timezone = $options['timezone'];
+			}
 		}
-		$inSeconds = self::fromString($dateTime, $userOffset);
+		$now = self::fromString(time(), $timezone);
+		$inSeconds = self::fromString($dateTime, $timezone);
 		$backwards = ($inSeconds > $now);
 
 		$format = 'j/n/y';
@@ -678,17 +699,17 @@ class CakeTime {
  * @param mixed $timeInterval the numeric value with space then time type.
  *    Example of valid types: 6 hours, 2 days, 1 minute.
  * @param mixed $dateString the datestring or unix timestamp to compare
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return boolean
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public static function wasWithinLast($timeInterval, $dateString, $userOffset = null) {
+	public static function wasWithinLast($timeInterval, $dateString, $timezone = null) {
 		$tmp = str_replace(' ', '', $timeInterval);
 		if (is_numeric($tmp)) {
 			$timeInterval = $tmp . ' ' . __d('cake', 'days');
 		}
 
-		$date = self::fromString($dateString, $userOffset);
+		$date = self::fromString($dateString, $timezone);
 		$interval = self::fromString('-' . $timeInterval);
 
 		if ($date >= $interval && $date <= time()) {
@@ -729,17 +750,17 @@ class CakeTime {
  * @param string $format date format string (or a DateTime string)
  * @param string $date Datetime string (or a date format string)
  * @param boolean $invalid flag to ignore results of fromString == false
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function format($format, $date = null, $invalid = false, $userOffset = null) {
-		$time = self::fromString($date, $userOffset);
-		$_time = self::fromString($format, $userOffset);
+	public static function format($format, $date = null, $invalid = false, $timezone = null) {
+		$time = self::fromString($date, $timezone);
+		$_time = self::fromString($format, $timezone);
 
 		if (is_numeric($_time) && $time === false) {
 			$format = $date;
-			return self::i18nFormat($_time, $format, $invalid, $userOffset);
+			return self::i18nFormat($_time, $format, $invalid, $timezone);
 		}
 		if ($time === false && $invalid !== false) {
 			return $invalid;
@@ -754,12 +775,12 @@ class CakeTime {
  * @param string $date Datetime string
  * @param string $format strftime format string.
  * @param boolean $invalid flag to ignore results of fromString == false
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone Timezone string or DateTimezone object
  * @return string Formatted and translated date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public static function i18nFormat($date, $format = null, $invalid = false, $userOffset = null) {
-		$date = self::fromString($date, $userOffset);
+	public static function i18nFormat($date, $format = null, $invalid = false, $timezone = null) {
+		$date = self::fromString($date, $timezone);
 		if ($date === false && $invalid !== false) {
 			return $invalid;
 		}

+ 54 - 54
lib/Cake/View/Helper/TimeHelper.php

@@ -137,12 +137,12 @@ class TimeHelper extends AppHelper {
  * @see CakeTime::convert()
  *
  * @param string $serverTime UNIX timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return integer UNIX timestamp
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function convert($serverTime, $userOffset) {
-		return $this->_engine->convert($serverTime, $userOffset);
+	public function convert($serverTime, $timezone) {
+		return $this->_engine->convert($serverTime, $timezone);
 	}
 
 /**
@@ -159,37 +159,37 @@ class TimeHelper extends AppHelper {
  * @see CakeTime::fromString()
  *
  * @param string $dateString Datetime string
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Parsed timestamp
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function fromString($dateString, $userOffset = null) {
-		return $this->_engine->fromString($dateString, $userOffset);
+	public function fromString($dateString, $timezone = null) {
+		return $this->_engine->fromString($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::nice()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @param string $format The format to use. If null, `TimeHelper::$niceFormat` is used
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function nice($dateString = null, $userOffset = null, $format = null) {
-		return $this->_engine->nice($dateString, $userOffset, $format);
+	public function nice($dateString = null, $timezone = null, $format = null) {
+		return $this->_engine->nice($dateString, $timezone, $format);
 	}
 
 /**
  * @see CakeTime::niceShort()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Described, relative date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function niceShort($dateString = null, $userOffset = null) {
-		return $this->_engine->niceShort($dateString, $userOffset);
+	public function niceShort($dateString = null, $timezone = null) {
+		return $this->_engine->niceShort($dateString, $timezone);
 	}
 
 /**
@@ -198,12 +198,12 @@ class TimeHelper extends AppHelper {
  * @param string $begin Datetime string or Unix timestamp
  * @param string $end Datetime string or Unix timestamp
  * @param string $fieldName Name of database field to compare with
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Partial SQL string.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function daysAsSql($begin, $end, $fieldName, $userOffset = null) {
-		return $this->_engine->daysAsSql($begin, $end, $fieldName, $userOffset);
+	public function daysAsSql($begin, $end, $fieldName, $timezone = null) {
+		return $this->_engine->daysAsSql($begin, $end, $fieldName, $timezone);
 	}
 
 /**
@@ -211,85 +211,85 @@ class TimeHelper extends AppHelper {
  *
  * @param string $dateString Datetime string or Unix timestamp
  * @param string $fieldName Name of database field to compare with
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Partial SQL string.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function dayAsSql($dateString, $fieldName, $userOffset = null) {
-		return $this->_engine->dayAsSql($dateString, $fieldName, $userOffset);
+	public function dayAsSql($dateString, $fieldName, $timezone = null) {
+		return $this->_engine->dayAsSql($dateString, $fieldName, $timezone);
 	}
 
 /**
  * @see CakeTime::isToday()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return boolean True if datetime string is today
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function isToday($dateString, $userOffset = null) {
-		return $this->_engine->isToday($dateString, $userOffset);
+	public function isToday($dateString, $timezone = null) {
+		return $this->_engine->isToday($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::isThisWeek()
  *
  * @param string $dateString
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return boolean True if datetime string is within current week
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function isThisWeek($dateString, $userOffset = null) {
-		return $this->_engine->isThisWeek($dateString, $userOffset);
+	public function isThisWeek($dateString, $timezone = null) {
+		return $this->_engine->isThisWeek($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::isThisMonth()
  *
  * @param string $dateString
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return boolean True if datetime string is within current month
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function isThisMonth($dateString, $userOffset = null) {
-		return $this->_engine->isThisMonth($dateString, $userOffset);
+	public function isThisMonth($dateString, $timezone = null) {
+		return $this->_engine->isThisMonth($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::isThisYear()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return boolean True if datetime string is within current year
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function isThisYear($dateString, $userOffset = null) {
-		return $this->_engine->isThisYear($dateString, $userOffset);
+	public function isThisYear($dateString, $timezone = null) {
+		return $this->_engine->isThisYear($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::wasYesterday()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return boolean True if datetime string was yesterday
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  *
  */
-	public function wasYesterday($dateString, $userOffset = null) {
-		return $this->_engine->wasYesterday($dateString, $userOffset);
+	public function wasYesterday($dateString, $timezone = null) {
+		return $this->_engine->wasYesterday($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::isTomorrow()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return boolean True if datetime string was yesterday
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function isTomorrow($dateString, $userOffset = null) {
-		return $this->_engine->isTomorrow($dateString, $userOffset);
+	public function isTomorrow($dateString, $timezone = null) {
+		return $this->_engine->isTomorrow($dateString, $timezone);
 	}
 
 /**
@@ -308,36 +308,36 @@ class TimeHelper extends AppHelper {
  * @see CakeTime::toUnix()
  *
  * @param string $dateString Datetime string to be represented as a Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return integer Unix timestamp
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function toUnix($dateString, $userOffset = null) {
-		return $this->_engine->toUnix($dateString, $userOffset);
+	public function toUnix($dateString, $timezone = null) {
+		return $this->_engine->toUnix($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::toAtom()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function toAtom($dateString, $userOffset = null) {
-		return $this->_engine->toAtom($dateString, $userOffset);
+	public function toAtom($dateString, $timezone = null) {
+		return $this->_engine->toAtom($dateString, $timezone);
 	}
 
 /**
  * @see CakeTime::toRSS()
  *
  * @param string $dateString Datetime string or Unix timestamp
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function toRSS($dateString, $userOffset = null) {
-		return $this->_engine->toRSS($dateString, $userOffset);
+	public function toRSS($dateString, $timezone = null) {
+		return $this->_engine->toRSS($dateString, $timezone);
 	}
 
 /**
@@ -358,12 +358,12 @@ class TimeHelper extends AppHelper {
  * @param mixed $timeInterval the numeric value with space then time type.
  *    Example of valid types: 6 hours, 2 days, 1 minute.
  * @param mixed $dateString the datestring or unix timestamp to compare
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return boolean
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function wasWithinLast($timeInterval, $dateString, $userOffset = null) {
-		return $this->_engine->wasWithinLast($timeInterval, $dateString, $userOffset);
+	public function wasWithinLast($timeInterval, $dateString, $timezone = null) {
+		return $this->_engine->wasWithinLast($timeInterval, $dateString, $timezone);
 	}
 
 /**
@@ -383,12 +383,12 @@ class TimeHelper extends AppHelper {
  * @param string $format date format string (or a DateTime string)
  * @param string $date Datetime string (or a date format string)
  * @param boolean $invalid flag to ignore results of fromString == false
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function format($format, $date = null, $invalid = false, $userOffset = null) {
-		return $this->_engine->format($format, $date, $invalid, $userOffset);
+	public function format($format, $date = null, $invalid = false, $timezone = null) {
+		return $this->_engine->format($format, $date, $invalid, $timezone);
 	}
 
 /**
@@ -397,12 +397,12 @@ class TimeHelper extends AppHelper {
  * @param string $date Datetime string
  * @param string $format strftime format string.
  * @param boolean $invalid flag to ignore results of fromString == false
- * @param integer $userOffset User's offset from GMT (in hours)
+ * @param mixed $timezone User's timezone string or DateTimeZone object
  * @return string Formatted and translated date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function i18nFormat($date, $format = null, $invalid = false, $userOffset = null) {
-		return $this->_engine->i18nFormat($date, $format, $invalid, $userOffset);
+	public function i18nFormat($date, $format = null, $invalid = false, $timezone = null) {
+		return $this->_engine->i18nFormat($date, $format, $invalid, $timezone);
 	}
 
 }