1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * Xoops\Core\Locale\Time - localized time handling
14: *
15: * @category Smarty_modifier
16: * @package modifier.datetime.php
17: * @author Richard Griffith <richard@geekwright.com>
18: * @copyright 2015 XOOPS Project (http://xoops.org)/
19: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
20: * @link http://xoops.org
21: */
22:
23: /**
24: * Smarty plugin to format a DateTime value
25: *
26: * Examples: {$datevariable|datetime} - Oct 19, 2015, 9:43:12 PM ('medium' is default)
27: * {$datevariable|datetime:'elapse'} - 2 days ago
28: * {$datevariable|datetime:'Y'} - 2015
29: *
30: * It is recommended to quote the format parameter
31: *
32: * @param \DateTime|int $datetime DateTime object, or unix timestamp
33: *
34: * @param string $format format as defined in Locale::formatTimestamp(). Valid formats include:
35: * short, medium, long, full, custom, elapse,
36: * short-date, medium-date, long-date, full-date,
37: * short-time, medium-time, long-time, full-time,
38: * rss, and PHP date() format string
39: *
40: * @return string formatted representation of $datetime
41: */
42: function smarty_modifier_datetime($datetime, $format = 'medium')
43: {
44: $string = \XoopsLocale::formatTimestamp($datetime, $format);
45: return $string;
46: }
47: