From ac6a0228118a2a9508489d26e5a72004acb41a15 Mon Sep 17 00:00:00 2001 From: mohrt Date: Thu, 29 Mar 2001 15:27:49 +0000 Subject: [PATCH] allow arbitrary date strings instead of just timestamps --- NEWS | 2 ++ Smarty.addons.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 17f208f4..3c8e52d2 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - allow arbitrary date strings to date_format, html_select_date and + html_select_time (Monte) Version 1.3.2 ------------- - fixed a bug that caused some nested includes to loop infinitely. (Andrei) diff --git a/Smarty.addons.php b/Smarty.addons.php index 4a81bf53..cb82c87f 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -133,7 +133,30 @@ function smarty_mod_spacify($string, $spacify_char = ' ') \*======================================================================*/ function smarty_mod_date_format($string, $format="%b %e, %Y") { - return strftime($format, $string); + return strftime($format, smarty_make_timestamp($string)); +} + +/*======================================================================*\ + Function: smarty_make_timestamp + Purpose: used by other smarty functions to make a timestamp + from a string of characters. +\*======================================================================*/ +function smarty_make_timestamp($string) +{ + $time = strtotime($string); + if(is_numeric($time) && $time != -1) + return $time; + + // is mysql timestamp format of YYYYMMDDHHMMSS? + if(is_numeric($string) && strlen($string) == 14) { + $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2), + substr($string,4,2),substr($string,6,2),substr($string,0,4)); + + return $time; + } + + // can decipher, must be timestamp already? + return $string; } /*======================================================================*\ @@ -249,6 +272,8 @@ function smarty_func_html_select_date() extract(func_get_arg(0)); + $time = smarty_make_timestamp($time); + $html_result = ""; if ($display_months) { @@ -316,6 +341,8 @@ function smarty_func_html_select_time() extract(func_get_arg(0)); + $time = smarty_make_timestamp($time); + $html_result = ''; if ($display_hours) {