From 0d013f8da5a80bae69e0a5375d3a2971b09a9db4 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 9 Jun 2012 08:28:39 -0430 Subject: [PATCH] Fixing CakeTime, the actual params for format() is $date and $format, and not the other way around :) --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 6 ++++++ lib/Cake/Utility/CakeTime.php | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 482aaf8dc..51c788e69 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -537,6 +537,12 @@ class CakeTimeTest extends CakeTestCase { $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); } /** diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 9a059eff8..3200d3b98 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -321,6 +321,10 @@ class CakeTime { $date = strtotime($dateString); } + if ($date === -1 || empty($date)) { + return false; + } + if ($timezone === null) { $timezone = Configure::read('Config.timezone'); } @@ -328,9 +332,6 @@ class CakeTime { if ($timezone !== null) { return self::convert($date, $timezone); } - if ($date === -1) { - return false; - } return $date; } @@ -927,25 +928,25 @@ class CakeTime { * 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); } /**