Created
December 4, 2013 20:45
-
-
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 ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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