summaryrefslogtreecommitdiff
path: root/smartyplugins/modifier.bit_date_format.php
blob: c996abac04cbb3eca3f5e26b5982780d72aa1806 (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
46
47
48
49
50
51
52
53
54
55
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

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

/**
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     modifier
 * Name:     bit_date_format
 * Purpose:  format datestamps via strftime, (timezone adjusted to administrator specified timezone)
 * Input:    string: input date string
 *           format: strftime format for output
 * -------------------------------------------------------------
 */
function smarty_modifier_bit_date_format( $pString, $format = "%b %e, %Y", $pTraFormat = "%b %e, %Y" ) {
	global $gBitSystem, $gBitUser, $gBitLanguage;

	if( empty( $pString )) {
		return '';
	}

	// we translate the entire date format string for total control
	if( $gBitSystem->getConfig( "bitlanguage", "en" ) != $gBitLanguage->mLanguage ) {
		$format = tra( $pTraFormat );
	}

	if( $gBitUser->getPreference( 'site_display_utc' ) == 'Fixed' && class_exists( 'DateTime' ) ) {
		date_default_timezone_set( $gBitUser->getPreference( 'site_display_timezone', 'UTC' ) );
		if ( is_numeric( $pString )) {
			$dateTimeUser = new DateTime( '@'.(int)$pString );
		} else  {
			$dateTimeUser = new DateTime( $pString );
		}
		$disptime = strtotime($dateTimeUser->format(DATE_W3C));
		return $gBitSystem->mServerTimestamp->strftime( $format, $disptime );
	} else {
		 if( $gBitSystem->get_display_offset() ) {
			$format = preg_replace( "/ ?%Z/",'', $format );
		} else {
			$format = preg_replace( "/%Z/", "UTC", $format );
		}
		$disptime = $gBitSystem->mServerTimestamp->getDisplayDateFromUTC( $pString );
	}
	return $gBitSystem->mServerTimestamp->strftime( $format, $disptime, TRUE );
}
?>