Ignore:
Timestamp:
Jun 20, 2013, 5:38:47 AM (11 years ago)
Author:
rvelices
Message:

smarty 3 - first pass for tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/smarty/libs/plugins/shared.make_timestamp.php

    r3282 r23384  
    22/**
    33 * Smarty shared plugin
     4 *
    45 * @package Smarty
    5  * @subpackage plugins
     6 * @subpackage PluginsShared
    67 */
    7 
    88
    99/**
    1010 * Function: smarty_make_timestamp<br>
    11  * Purpose:  used by other smarty functions to make a timestamp
    12  *           from a string.
     11 * Purpose:  used by other smarty functions to make a timestamp from a string.
     12 *
    1313 * @author   Monte Ohrt <monte at ohrt dot com>
    14  * @param string
    15  * @return string
     14 * @param DateTime|int|string $string  date object, timestamp or string that can be converted using strtotime()
     15 * @return int
    1616 */
    1717function smarty_make_timestamp($string)
    1818{
    19     if(empty($string)) {
     19    if (empty($string)) {
    2020        // use "now":
    21         $time = time();
    22 
    23     } elseif (preg_match('/^\d{14}$/', $string)) {
    24         // it is mysql timestamp format of YYYYMMDDHHMMSS?           
    25         $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
     21        return time();
     22    } elseif ($string instanceof DateTime) {
     23        return $string->getTimestamp();
     24    } elseif (strlen($string) == 14 && ctype_digit($string)) {
     25        // it is mysql timestamp format of YYYYMMDDHHMMSS?
     26        return mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
    2627                       substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));
    27        
    2828    } elseif (is_numeric($string)) {
    2929        // it is a numeric string, we handle it as timestamp
    30         $time = (int)$string;
    31        
     30        return (int) $string;
    3231    } else {
    3332        // strtotime should handle it
     
    3534        if ($time == -1 || $time === false) {
    3635            // strtotime() was not able to parse $string, use "now":
    37             $time = time();
     36            return time();
    3837        }
     38        return $time;
    3939    }
    40     return $time;
    41 
    4240}
    4341
    44 /* vim: set expandtab: */
    45 
    4642?>
Note: See TracChangeset for help on using the changeset viewer.