cvs: smarty /docs designers.sgml /plugins modifier.date_format.php
| From: | Monte Ohrt | Date: | Wed, 19 Jun 2002 14:43:59 +0000 |
| Subject: | cvs: smarty /docs designers.sgml /plugins modifier.date_format.php | ||
| Groups: | php.smarty.cvs | ||
| Request: | Send a blank email to php-smarty-cvs+get-145@lists.php.net to get a copy of this message | ||
mohrt Wed Jun 19 10:43:59 2002 EDT
Modified files:
/smarty/docs designers.sgml
/smarty/plugins modifier.date_format.php
Log:
update date_format, allow optional 2nd paramater as default date if passed date is empty. update
docs.
Index: smarty/docs/designers.sgml
diff -u smarty/docs/designers.sgml:1.33 smarty/docs/designers.sgml:1.34
--- smarty/docs/designers.sgml:1.33 Thu Jun 6 10:21:45 2002
+++ smarty/docs/designers.sgml Wed Jun 19 10:43:55 2002
@@ -479,6 +479,13 @@
<entry>%b %e, %Y</entry>
<entry>This is the format for the outputted date.</entry>
</row>
+ <row>
+ <entry>2</entry>
+ <entry>string</entry>
+ <entry>No</entry>
+ <entry>n/a</entry>
+ <entry>This is the default date if the input is empty.</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
@@ -487,7 +494,9 @@
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.
</para>
<example>
<title>date_format</title>
@@ -495,12 +504,15 @@
{$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</programlisting>
+14:33:00
+22:23:12</programlisting>
</example>
<example>
<title>date_format conversion specifiers</title>
Index: smarty/plugins/modifier.date_format.php
diff -u smarty/plugins/modifier.date_format.php:1.5 smarty/plugins/modifier.date_format.php:1.6
--- smarty/plugins/modifier.date_format.php:1.5 Wed Jun 19 10:25:01 2002
+++ smarty/plugins/modifier.date_format.php Wed Jun 19 10:43:58 2002
@@ -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;
}