mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge remote branch 'origin/2.0' into 2.0-class-loading
This commit is contained in:
commit
599a110d6b
3 changed files with 42 additions and 3 deletions
|
@ -29,6 +29,31 @@ App::uses('AppHelper', 'View/Helper');
|
|||
*/
|
||||
class TimeHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* The format to use when formatting a time using `TimeHelper::nice()`
|
||||
*
|
||||
* The format should use the locale strings as defined in the PHP docs under
|
||||
* `strftime` (http://php.net/manual/en/function.strftime.php)
|
||||
*
|
||||
* @var string
|
||||
* @see TimeHelper::format()
|
||||
*/
|
||||
public $niceFormat = '%a, %b %eS %Y, %H:%M';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param View $View the view object the helper is attached to.
|
||||
* @param array $settings Settings array Settings array
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(View $View, $settings = array()) {
|
||||
if (isset($settings['niceFormat'])) {
|
||||
$this->niceFormat = $settings['niceFormat'];
|
||||
}
|
||||
parent::__construct($View, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string representing the format for the function strftime and returns a
|
||||
* windows safe and i18n aware format.
|
||||
|
@ -188,19 +213,26 @@ class TimeHelper extends AppHelper {
|
|||
/**
|
||||
* Returns a nicely formatted date string for given Datetime string.
|
||||
*
|
||||
* See http://php.net/manual/en/function.strftime.php for information on formatting
|
||||
* using locale strings.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @param string $format The format to use. If null, `TimeHelper::$niceFormat` is used
|
||||
* @return string Formatted date string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
public function nice($dateString = null, $userOffset = null) {
|
||||
public function nice($dateString = null, $userOffset = null, $format = null) {
|
||||
if ($dateString != null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
} else {
|
||||
$date = time();
|
||||
}
|
||||
$format = $this->convertSpecifiers('%a, %b %eS %Y, %H:%M', $date);
|
||||
if (!$format) {
|
||||
$format = $this->niceFormat;
|
||||
}
|
||||
$format = $this->convertSpecifiers($format, $date);
|
||||
return strftime($format, $date);
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class TemplateTaskTest extends CakeTestCase {
|
|||
public function testFindingInstalledThemesForBake() {
|
||||
$consoleLibs = CAKE . 'console' . DS;
|
||||
$this->Task->initialize();
|
||||
$this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS));
|
||||
$this->assertEqual($this->Task->templatePaths['default'], $consoleLibs . 'templates' . DS . 'default' . DS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -324,6 +324,13 @@ class TimeHelperTest extends CakeTestCase {
|
|||
|
||||
$time = null;
|
||||
$this->assertEqual(date('D, M jS Y, H:i', time()), $this->Time->nice($time));
|
||||
|
||||
$time = time();
|
||||
$this->assertEqual(date('D', $time), $this->Time->nice($time, null, '%a'));
|
||||
$this->assertEqual(date('M d, Y', $time), $this->Time->nice($time, null, '%b %d, %Y'));
|
||||
|
||||
$this->Time->niceFormat = '%Y-%d-%m';
|
||||
$this->assertEqual(date('Y-d-m', $time), $this->Time->nice($time));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue