mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing CakeTime, the actual params for format() is $date and $format,
and not the other way around :)
This commit is contained in:
parent
c8e58b50ba
commit
0d013f8da5
2 changed files with 16 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue