1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: |
|
29: | function smarty_modifier_date_format($string, $format = null, $default_date = '', $formatter = 'auto')
|
30: | {
|
31: | if ($format === null) {
|
32: | $format = Smarty::$_DATE_FORMAT;
|
33: | }
|
34: | |
35: | |
36: |
|
37: | static $is_loaded = false;
|
38: | if (!$is_loaded) {
|
39: | if (!is_callable('smarty_make_timestamp')) {
|
40: | include_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
|
41: | }
|
42: | $is_loaded = true;
|
43: | }
|
44: | if (!empty($string) && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
|
45: | $timestamp = smarty_make_timestamp($string);
|
46: | } elseif (!empty($default_date)) {
|
47: | $timestamp = smarty_make_timestamp($default_date);
|
48: | } else {
|
49: | return;
|
50: | }
|
51: | if ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
|
52: | if (Smarty::$_IS_WINDOWS) {
|
53: | $_win_from = array(
|
54: | '%D',
|
55: | '%h',
|
56: | '%n',
|
57: | '%r',
|
58: | '%R',
|
59: | '%t',
|
60: | '%T'
|
61: | );
|
62: | $_win_to = array(
|
63: | '%m/%d/%y',
|
64: | '%b',
|
65: | "\n",
|
66: | '%I:%M:%S %p',
|
67: | '%H:%M',
|
68: | "\t",
|
69: | '%H:%M:%S'
|
70: | );
|
71: | if (strpos($format, '%e') !== false) {
|
72: | $_win_from[] = '%e';
|
73: | $_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
|
74: | }
|
75: | if (strpos($format, '%l') !== false) {
|
76: | $_win_from[] = '%l';
|
77: | $_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
|
78: | }
|
79: | $format = str_replace($_win_from, $_win_to, $format);
|
80: | }
|
81: | return strftime($format, $timestamp);
|
82: | } else {
|
83: | return date($format, $timestamp);
|
84: | }
|
85: | }
|
86: | |