6 * @subpackage PluginsModifier
10 * Smarty date_format modifier plugin
13 * Name: date_format<br>
14 * Purpose: format datestamps via strftime<br>
16 * - string: input date string
17 * - format: strftime format for output
18 * - default_date: default date if $string is empty
20 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
21 * @author Monte Ohrt <monte at ohrt dot com>
25 * @return string |void
26 * @uses smarty_make_timestamp()
28 function smarty_modifier_date_format($string, $format = SMARTY_RESOURCE_DATE_FORMAT, $default_date = '',$formatter='auto')
31 * Include the {@link shared.make_timestamp.php} plugin
33 require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
35 $timestamp = smarty_make_timestamp($string);
36 } elseif ($default_date != '') {
37 $timestamp = smarty_make_timestamp($default_date);
41 if($formatter=='strftime'||($formatter=='auto'&&strpos($format,'%')!==false)) {
43 $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
44 $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
45 if (strpos($format, '%e') !== false) {
47 $_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
49 if (strpos($format, '%l') !== false) {
51 $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
53 $format = str_replace($_win_from, $_win_to, $format);
55 return strftime($format, $timestamp);
57 return date($format, $timestamp);