Skip to content

Instantly share code, notes, and snippets.

@Suven
Created December 4, 2013 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suven/7795199 to your computer and use it in GitHub Desktop.
Save Suven/7795199 to your computer and use it in GitHub Desktop.
Introduces an additional parameter $onlyDate to niceShort. Set it to true to hide the time-information. I bet it could be done much better (i.e. without the additional parameter).. Let me know, if you know how ;)
<?php
App::uses('TimeHelper', 'View/Helper');
/**
* CustomTimeHelper.
*
* Introduces an additional parameter $onlyDate to niceShort.
* Set it to true to hide the time-information.
*
* To use it, just save this file in /app/View/Helper/CustomTimeHelper.php
* and add the following code to your AppController:
* public $helpers = array(
* 'Time' => array(
* 'className' => 'CustomTime'
* )
* );
*
* @link https://gist.github.com/Suven/
*/
class CustomTimeHelper extends TimeHelper {
public function niceShort($dateString = null, $timezone = null, $onlyDate = false) {
if ($onlyDate) {
$nice = parent::niceShort($dateString, $timezone);
return substr($nice,0,strpos($nice,","));
} else {
return parent::niceShort($dateString, $timezone);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment