summaryrefslogtreecommitdiff
path: root/smartyplugins/modifier.cal_date_format.php
blob: f213a35b2037c2f94965722f50876d0f99dd0bfc (plain)
1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Bitweaver\Plugins;

use Bitweaver\BitDate;

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * required setup
 */
global $gBitSmarty;
// $gBitSmarty->loadPlugin('smarty_shared_make_timestamp');

/**
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     modifier
 * Name:     cal_date_format
 * Purpose:  format datestamps via strftime, (timezone adjusted to calendar specified timezone)
 * Input:    string: input date string
 *           format: strftime format for output
 *           default_date: default date if $string is empty
 * -------------------------------------------------------------
 */
function smarty_modifier_cal_date_format($string, $format = "%b %e, %Y", $default_date=null, $tra_format=null)
{
	$mDate = new BitDate(0);
	$format =  $mDate->get_display_offset()
		? preg_replace("/ ?%Z/","",$format)
		: preg_replace("/%Z/","UTC",$format);

	$disptime = $mDate->getTimestampFromISO($string);

	global $gBitSystem, $gBitLanguage; //$gBitLanguage->mLanguage= $gBitSystem->getConfig("language", "en");
	if ($gBitSystem->getConfig("language", "en") != $gBitLanguage->mLanguage && $tra_format) {
		$format = $tra_format;
	}
	return $mDate->strftime($format, $disptime, true);
}

/* vim: set expandtab: */