Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

modifier date_tz_format

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Jan 07, 2005 9:43 pm    Post subject: modifier date_tz_format Reply with quote

This is a plugin for displaying dates relative to a timezone other than the localtime. Usage:

Code:
{$mydate|date_tz_format:"US/Mountain":"%Y-%m-%d %H:%M:%S"}


This will show the $mydate value as it would be in Mountain time. This plugin relies on a proper zoneinfo database, see the PHP manual for more info on handling timezone information.

[php:1:dec16ce5e7]<?php

/*
* Smarty plugin
* -------------------------------------------------------------
* Type: modifier
* Name: date_tz_format
* Purpose: format datestamps via strftime in given timezone
* Author: Monte Ohrt (monte@ispi.net)
* Version: 1.0
* Date: January 7th, 2005
* Example: {$mydate|date_tz_format:"US/Central":"%Y-%m-%d %H:%M:%S"}
* Input: string: input date string
* timezone: timezone to output
* format: strftime format for output
* default_date: default date if $string is empty
* -------------------------------------------------------------
*/
require_once $this->_get_plugin_filepath('shared','make_timestamp');
function smarty_modifier_date_tz_format($string, $tz, $format="%b %e, %Y", $default_date=null)
{
if(empty($tz))
$tz = getenv('TZ');

if($string != '') {
$_local_timestamp = smarty_make_timestamp($string);
} elseif (isset($default_date) && $default_date != '') {
$_local_timestamp = smarty_make_timestamp($default_date);
} else {
return;
}

$_local_tz = getenv('TZ');

putenv('TZ=' . $tz);

$_output = strftime($format, $_local_timestamp);

putenv('TZ=' . $_local_tz);

return $_output;

}

/* vim: set expandtab: */

?>[/php:1:dec16ce5e7]
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP