From bd96ebf984b58ce42939920a0a2bbcc30cf9c450 Mon Sep 17 00:00:00 2001 From: mohrt Date: Wed, 19 Jun 2002 14:43:58 +0000 Subject: [PATCH] update date_format, allow optional 2nd paramater as default date if passed date is empty. update docs. --- docs/designers.sgml | 16 ++++++++++++++-- libs/plugins/modifier.date_format.php | 7 ++++++- plugins/modifier.date_format.php | 7 ++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/designers.sgml b/docs/designers.sgml index 833dc7d2..cc478539 100644 --- a/docs/designers.sgml +++ b/docs/designers.sgml @@ -479,6 +479,13 @@ Dealers Will Hear Car Talk at Noon. %b %e, %Y This is the format for the outputted date. + + 2 + string + No + n/a + This is the default date if the input is empty. + @@ -487,7 +494,9 @@ Dealers Will Hear Car Talk at Noon. Dates can be passed to Smarty as unix timestamps, mysql timestamps or any string made up of month day year (parsable by strtotime). Designers can then use date_format to have complete control of the - formatting of the date. + formatting of the date. If the date passed to date_format is empty + and a second paramter is passed, that will be used as the date to + format. date_format @@ -495,12 +504,15 @@ Dealers Will Hear Car Talk at Noon. {$currentDate} {$currentDate|date_format:"%A, %B %e, %Y"} {$currentDate|date_format:"%H:%M:%S"} +{* format current time if $currentDate is empty *} +{$currentDate|date_format:"%H:%M:%S":"now"} OUTPUT: Feb 6, 2001 Tuesday, February 6, 2001 -14:33:00 +14:33:00 +22:23:12 date_format conversion specifiers diff --git a/libs/plugins/modifier.date_format.php b/libs/plugins/modifier.date_format.php index 4f85b030..d9069727 100644 --- a/libs/plugins/modifier.date_format.php +++ b/libs/plugins/modifier.date_format.php @@ -6,13 +6,18 @@ * Type: modifier * Name: date_format * Purpose: format datestamps via strftime + * Input: string: input date string + * format: strftime format for output + * default_date: default date if $string is empty * ------------------------------------------------------------- */ require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; -function smarty_modifier_date_format($string, $format="%b %e, %Y") +function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null) { if($string != '') { return strftime($format, smarty_make_timestamp($string)); + } elseif (isset($default_date) && $default_date != '') { + return strftime($format, smarty_make_timestamp($default_date)); } else { return; } diff --git a/plugins/modifier.date_format.php b/plugins/modifier.date_format.php index 4f85b030..d9069727 100644 --- a/plugins/modifier.date_format.php +++ b/plugins/modifier.date_format.php @@ -6,13 +6,18 @@ * Type: modifier * Name: date_format * Purpose: format datestamps via strftime + * Input: string: input date string + * format: strftime format for output + * default_date: default date if $string is empty * ------------------------------------------------------------- */ require_once SMARTY_DIR . $this->plugins_dir . '/shared.make_timestamp.php'; -function smarty_modifier_date_format($string, $format="%b %e, %Y") +function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null) { if($string != '') { return strftime($format, smarty_make_timestamp($string)); + } elseif (isset($default_date) && $default_date != '') { + return strftime($format, smarty_make_timestamp($default_date)); } else { return; }