X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=branches%2Fold%2Fgosa-core%2Finclude%2Fsmarty%2Fplugins%2Fshared.make_timestamp.php;fp=branches%2Fold%2Fgosa-core%2Finclude%2Fsmarty%2Fplugins%2Fshared.make_timestamp.php;h=b42eb11d85d1b6f0a5a2064d88f102d958dfd302;hb=cff5b6e974405f455a90de3a3fc6cc7b084ffe10;hp=0000000000000000000000000000000000000000;hpb=2ad05dfc09e8a07d6e6886604458f475c9c8f2f8;p=gosa.git diff --git a/branches/old/gosa-core/include/smarty/plugins/shared.make_timestamp.php b/branches/old/gosa-core/include/smarty/plugins/shared.make_timestamp.php new file mode 100644 index 000000000..b42eb11d8 --- /dev/null +++ b/branches/old/gosa-core/include/smarty/plugins/shared.make_timestamp.php @@ -0,0 +1,46 @@ + + * Purpose: used by other smarty functions to make a timestamp + * from a string. + * @author Monte Ohrt + * @param string + * @return string + */ +function smarty_make_timestamp($string) +{ + if(empty($string)) { + // use "now": + $time = time(); + + } elseif (preg_match('/^\d{14}$/', $string)) { + // it is mysql timestamp format of YYYYMMDDHHMMSS? + $time = mktime(substr($string, 8, 2),substr($string, 10, 2),substr($string, 12, 2), + substr($string, 4, 2),substr($string, 6, 2),substr($string, 0, 4)); + + } elseif (is_numeric($string)) { + // it is a numeric string, we handle it as timestamp + $time = (int)$string; + + } else { + // strtotime should handle it + $time = strtotime($string); + if ($time == -1 || $time === false) { + // strtotime() was not able to parse $string, use "now": + $time = time(); + } + } + return $time; + +} + +/* vim: set expandtab: */ + +?>