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

utcdate_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
Hinrich
Smarty Rookie


Joined: 18 Apr 2003
Posts: 33

PostPosted: Wed Jun 11, 2003 2:42 pm    Post subject: utcdate_format Reply with quote

Hi,

nothing serious, but sometimes you need the UTC date or time in your plugins. I just copied the modifier date_format to a new modifier called utcdate_format. The usage is identical.

Code:
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Include the {@link shared.make_timestamp.php} plugin
 */
require_once $this->_get_plugin_filepath('shared','make_timestamp');
/**
 * Smarty utc date_format modifier plugin
 *
 * Type:     modifier<br>
 * Name:     utcdate_format<br>
 * Purpose:  format datestamps via gmstrftime<br>
 * Input:<br>
 *         - string: input date string
 *         - format: gmstrftime format for output
 *         - default_date: default date if $string is empty
 * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
 *          date_format (Smarty online manual)
 * @param string
 * @param string
 * @param string
 * @return string|void
 * @uses smarty_make_timestamp()
 */
function smarty_modifier_utcdate_format($string, $format="%b %e, %Y", $default_date=null)
{
    if($string != '') {
        return gmstrftime($format, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
        return gmstrftime($format, smarty_make_timestamp($default_date));
    } else {
        return;
    }
}

/* vim: set expandtab: */

?>


Would be nice, if it will be shipped to the package somewhen.
Back to top
View user's profile Send private message
joscha
Smarty Rookie


Joined: 18 Apr 2003
Posts: 8
Location: Metzingen, Germany

PostPosted: Wed Jun 11, 2003 11:29 pm    Post subject: Reply with quote

Hi Hinrich,

nice work!

The package should be as small as possible, just add it to the Smarty-wiki so everyone can find it!

greets,
Joscha
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Thu Jun 12, 2003 2:45 am    Post subject: Reply with quote

Maybe we could add to the tools instead of duplicate, like this:

Code:
{$smarty.now|utc|date_format}


So all "utc" does is gets the date into UTC time, then on to date_format as usual.

Monte
Back to top
View user's profile Send private message Visit poster's website
Hinrich
Smarty Rookie


Joined: 18 Apr 2003
Posts: 33

PostPosted: Thu Jun 12, 2003 8:57 am    Post subject: Reply with quote

mohrt wrote:
Maybe we could add to the tools instead of duplicate, like this:

Code:
{$smarty.now|utc|date_format}


On the other hand gmstrftime is a native PHP function and should be faster than passing the variable through two modifieres.
Back to top
View user's profile Send private message
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Thu Dec 04, 2003 12:16 pm    Post subject: Reply with quote

This fails for dates before 1970 usually. Would be better if the whole of Smartys date handling was based around somthing like the PEAR::Date class which can cope better with pre-1970 dates.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Hinrich
Smarty Rookie


Joined: 18 Apr 2003
Posts: 33

PostPosted: Thu Dec 04, 2003 12:49 pm    Post subject: Reply with quote

Budda wrote:
This fails for dates before 1970 usually.


It depends on your need. Imho in most cases nobody will need an UTC before 1970; most reviews aren't haveing any time information. In most cases I think, UTC is used for current or future time stamps in a for example calender. In this case, the modifier is called often and the execution time does matter.

So it allways depends on the individual usage.
Back to top
View user's profile Send private message
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