Permalink
Browse files

Fixing CakeTime, the actual params for format() is $date and $format,

and not the other way around :)
  • Loading branch information...
1 parent c8e58b5 commit 0d013f8da5a80bae69e0a5375d3a2971b09a9db4 @lorenzo lorenzo committed Jun 9, 2012
Showing with 16 additions and 9 deletions.
  1. +6 −0 lib/Cake/Test/Case/Utility/CakeTimeTest.php
  2. +10 −9 lib/Cake/Utility/CakeTime.php
@@ -537,6 +537,12 @@ public function testFormat() {
$result = $this->Time->format('Y-m-d', null, 'never');
$this->assertEquals('never', $result);
+
+ $result = $this->Time->format('2012-01-13', '%d-%m-%Y', 'invalid', 'UTC');
+ $this->assertEquals('13-01-2012', $result);
+
+ $result = $this->Time->format('nonsense', '%d-%m-%Y', 'invalid', 'UTC');
+ $this->assertEquals('invalid', $result);
}
/**
@@ -321,16 +321,17 @@ public static function fromString($dateString, $timezone = null) {
$date = strtotime($dateString);
}
+ if ($date === -1 || empty($date)) {
+ return false;
+ }
+
if ($timezone === null) {
$timezone = Configure::read('Config.timezone');
}
if ($timezone !== null) {
return self::convert($date, $timezone);
}
- if ($date === -1) {
- return false;
- }
return $date;
}
@@ -927,25 +928,25 @@ public static function gmt($dateString = null) {
* This function also accepts a time string and a format string as first and second parameters.
* In that case this function behaves as a wrapper for TimeHelper::i18nFormat()
*
- * @param integer|string|DateTime $format date format string (or UNIX timestamp, strtotime() valid string or DateTime object)
* @param integer|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
+ * @param integer|string|DateTime $format date format string (or UNIX timestamp, strtotime() valid string or DateTime object)
* @param boolean $invalid flag to ignore results of fromString == false
* @param string|DateTimeZone $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, $timezone = null) {
- $time = self::fromString($date, $timezone);
- $_time = is_numeric($time) ? false : self::fromString($format, $timezone);
+ public static function format($date, $format = null, $invalid = false, $timezone = null) {
+ //Backwards compatible params order
+ $time = self::fromString($format, $timezone);
+ $_time = is_numeric($time) ? false : self::fromString($date, $timezone);
if (is_numeric($_time) && $time === false) {
- $format = $date;
return self::i18nFormat($_time, $format, $invalid, $timezone);
}
if ($time === false && $invalid !== false) {
return $invalid;
}
- return date($format, $time);
+ return date($date, $time);
}
/**

0 comments on commit 0d013f8

Please sign in to comment.