mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
update date_format, allow optional 2nd paramater as default date if passed date is empty. update docs.
This commit is contained in:
@@ -479,6 +479,13 @@ Dealers Will Hear Car Talk at Noon.
|
|||||||
<entry>%b %e, %Y</entry>
|
<entry>%b %e, %Y</entry>
|
||||||
<entry>This is the format for the outputted date.</entry>
|
<entry>This is the format for the outputted date.</entry>
|
||||||
</row>
|
</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>
|
</tbody>
|
||||||
</tgroup>
|
</tgroup>
|
||||||
</informaltable>
|
</informaltable>
|
||||||
@@ -487,7 +494,9 @@ Dealers Will Hear Car Talk at Noon.
|
|||||||
Dates can be passed to Smarty as unix timestamps, mysql timestamps
|
Dates can be passed to Smarty as unix timestamps, mysql timestamps
|
||||||
or any string made up of month day year (parsable by strtotime).
|
or any string made up of month day year (parsable by strtotime).
|
||||||
Designers can then use date_format to have complete control of the
|
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>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>date_format</title>
|
<title>date_format</title>
|
||||||
@@ -495,12 +504,15 @@ Dealers Will Hear Car Talk at Noon.
|
|||||||
{$currentDate}
|
{$currentDate}
|
||||||
{$currentDate|date_format:"%A, %B %e, %Y"}
|
{$currentDate|date_format:"%A, %B %e, %Y"}
|
||||||
{$currentDate|date_format:"%H:%M:%S"}
|
{$currentDate|date_format:"%H:%M:%S"}
|
||||||
|
{* format current time if $currentDate is empty *}
|
||||||
|
{$currentDate|date_format:"%H:%M:%S":"now"}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
Feb 6, 2001
|
Feb 6, 2001
|
||||||
Tuesday, February 6, 2001
|
Tuesday, February 6, 2001
|
||||||
14:33:00</programlisting>
|
14:33:00
|
||||||
|
22:23:12</programlisting>
|
||||||
</example>
|
</example>
|
||||||
<example>
|
<example>
|
||||||
<title>date_format conversion specifiers</title>
|
<title>date_format conversion specifiers</title>
|
||||||
|
@@ -6,13 +6,18 @@
|
|||||||
* Type: modifier
|
* Type: modifier
|
||||||
* Name: date_format
|
* Name: date_format
|
||||||
* Purpose: format datestamps via strftime
|
* 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';
|
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 != '') {
|
if($string != '') {
|
||||||
return strftime($format, smarty_make_timestamp($string));
|
return strftime($format, smarty_make_timestamp($string));
|
||||||
|
} elseif (isset($default_date) && $default_date != '') {
|
||||||
|
return strftime($format, smarty_make_timestamp($default_date));
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -6,13 +6,18 @@
|
|||||||
* Type: modifier
|
* Type: modifier
|
||||||
* Name: date_format
|
* Name: date_format
|
||||||
* Purpose: format datestamps via strftime
|
* 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';
|
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 != '') {
|
if($string != '') {
|
||||||
return strftime($format, smarty_make_timestamp($string));
|
return strftime($format, smarty_make_timestamp($string));
|
||||||
|
} elseif (isset($default_date) && $default_date != '') {
|
||||||
|
return strftime($format, smarty_make_timestamp($default_date));
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user