Permalink
Browse files

Renaming param in CakeTime::format() to make its purpose more obvious,

added some examples in doc block
  • Loading branch information...
1 parent 0d013f8 commit a2c2902dd60bb8a51edb264f2686ed96a63bdf92 @lorenzo lorenzo committed Jun 9, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/Cake/Utility/CakeTime.php
@@ -928,14 +928,22 @@ public static function gmt($dateString = null) {
* 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()
*
+ * ## Examples:
+ * {{{
+ * CakeTime::format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012
+ * CakeTime::format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale
+ * CakeTime::format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A becuase an invalid date was passed
+ * CakeTime::format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone
+ * }}}
+ *
* @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 boolean|string $default if an invalid date is passed it will output supplied default value. Pass false if you want raw conversion value
* @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($date, $format = null, $invalid = false, $timezone = null) {
+ public static function format($date, $format = null, $default = false, $timezone = null) {
//Backwards compatible params order
$time = self::fromString($format, $timezone);
$_time = is_numeric($time) ? false : self::fromString($date, $timezone);
@@ -955,12 +963,12 @@ public static function format($date, $format = null, $invalid = false, $timezone
*
* @param integer|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
* @param string $format strftime format string.
- * @param boolean $invalid flag to ignore results of fromString == false
+ * @param boolean|string $default if an invalid date is passed it will output supplied default value. Pass false if you want raw conversion value
* @param string|DateTimeZone $timezone Timezone string or DateTimeZone object
* @return string Formatted and translated date string
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
- public static function i18nFormat($date, $format = null, $invalid = false, $timezone = null) {
+ public static function i18nFormat($date, $format = null, $default = false, $timezone = null) {
$date = self::fromString($date, $timezone);
if ($date === false && $invalid !== false) {
@ADmad

ADmad Jun 9, 2012

Member

Forgot to change the actual param usage in the function :)

return $invalid;

2 comments on commit a2c2902

Member

ADmad commented on a2c2902 Jun 9, 2012

Should probably make similar param name and docblock changes in TimeHelper class too

Owner

lorenzo replied Jun 9, 2012

Will do, thanks!

Please sign in to comment.