Re: [SMARTY] date offset

From: Date: Sun, 02 Jan 2005 05:40:12 +0000
Subject: Re: [SMARTY] date offset
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12095@lists.php.net to get a copy of this message
I wrote:
Does anyone have any ideas, and could something like the above be included in the next Smarty release?
messju wrote
i prefer setlocale(LC_TIME, '...') over arithmetics with the timestamp to localize date_format for a specific timezone.
I feel the same way, but setlocale() doesn't seem to be reliable -- it depends on the server configuration, which is not always under the control of the application administrator. Furthermore, there seems to be no definitive way to specify any single locale -- just read the comments at http://us2.php.net/setlocale: "On Windows XP (maybe W2K too) set it to "German", and on an Unixserver it work with "de" ... Primary I was confused, cause everyone say it should be "de_DE". "OS X 10.2 does not have complete locale support: navigating to /usr/share/locale shows all the locale directories one might expect, but these don't contain all the same files as other flavors of Unix." "In hope to help other danes (who else would need our lang.code?!), here is the language-code for FreeBSD: setlocale (LC_ALL, 'da_DK.ISO8859-1');" The comments go on and on...until that is more reliable, I'd much rather allow the application administrator to enter a numeric value for the time offset. So, I ask again...could the offset capability be added to the date_format modifier in Smarty? It certainly wouldn't hurt you if you preferred to use setlocale(), but it would certainly help if you didn't. cheers, Travis messju mohr wrote:
On Sat, Jan 01, 2005 at 01:29:12AM -0500, Travis Low wrote:
Happy new year, everyone. I have a customer in Australia who uses a server in California. I'd like to give them a configurable offset value (plus or minus hours) that could be used to change the time they're seeing. I know I could muck with the time from within the application itself, but ultimately, I think it would be better if the end-user could set the value, so that (for example) users in different timezones can adjust the times to suit their locale. Here is a hack of modifier.date_format.php that seems to work: function smarty_modifier_date_format($string, $format="%b %e, %Y", $offset=0, $default_date=null) {
       echo "<h1>$offset</h1>";
if($string != '') {
       return strftime($format, smarty_make_timestamp($string) +        ($offset*3600));
} elseif (isset($default_date) && $default_date != '') {
       return strftime($format, smarty_make_timestamp($default_date) + ($offset*3600));
} else {
       return;
} } Unfortunately, I couldn't get it to work without swapping $offset and $default_date, and I fear that may break existing code.
you can pass null as {$var|date_format:"... %Y":null:$offset} and keep the old argument order.
Does anyone have any ideas, and could something like the above be included in the next Smarty release?
i prefer setlocale(LC_TIME, '...') over arithmetics with the timestamp to localize date_format for a specific timezone. greetings messju
cheers, Travis -- Travis Low <mailto:travis@dawnstar.com> <http://www.dawnstar.com> -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Travis Low <mailto:travis@dawnstar.com> <http://www.dawnstar.com>

« previous php.smarty.general (#12095) next »