~ubuntu-branches/ubuntu/gutsy/smarty/gutsy-security

« back to all changes in this revision

Viewing changes to libs/plugins/shared.make_timestamp.php

  • Committer: Bazaar Package Importer
  • Author(s): Igor Genibel
  • Date: 2005-11-02 19:08:30 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20051102190830-8jm4nqv2fivcq9si
Tags: 2.6.10-0.2
* Non-maintainer upload (with maintainer permission: 0-day NMU).
* Change Maintainer address

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
function smarty_make_timestamp($string)
17
17
{
18
18
    if(empty($string)) {
19
 
        $string = "now";
20
 
    }
21
 
    $time = strtotime($string);
22
 
    if (is_numeric($time) && $time != -1)
23
 
        return $time;
24
 
 
25
 
    // is mysql timestamp format of YYYYMMDDHHMMSS?
26
 
    if (preg_match('/^\d{14}$/', $string)) {
27
 
        $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
28
 
               substr($string,4,2),substr($string,6,2),substr($string,0,4));
29
 
 
30
 
        return $time;
31
 
    }
32
 
 
33
 
    // couldn't recognize it, try to return a time
34
 
    $time = (int) $string;
35
 
    if ($time > 0)
36
 
        return $time;
37
 
    else
38
 
        return time();
 
19
        // use "now":
 
20
        $time = time();
 
21
 
 
22
    } elseif (preg_match('/^\d{14}$/', $string)) {
 
23
        // it is mysql timestamp format of YYYYMMDDHHMMSS?            
 
24
        $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2),
 
25
                       substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4));
 
26
        
 
27
    } elseif (is_numeric($string)) {
 
28
        // it is a numeric string, we handle it as timestamp
 
29
        $time = (int)$string;
 
30
        
 
31
    } else {
 
32
        // strtotime should handle it
 
33
        $time = strtotime($string);
 
34
        if ($time == -1 || $time === false) {
 
35
            // strtotime() was not able to parse $string, use "now":
 
36
            $time = time();
 
37
        }
 
38
    }
 
39
    return $time;
 
40
 
39
41
}
40
42
 
41
43
/* vim: set expandtab: */