diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-07-04 09:08:54 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-07-04 09:08:54 +0200 |
commit | dd6f32b3b506d29da38f41d307e5ea217c21cb51 (patch) | |
tree | 1d6df50a08b152328bb8df4b4b0e52635ec0193d /system | |
parent | f2dcca6f9212923e54fb62ae58f79dc713b111ad (diff) |
Optimize standard_date()
Diffstat (limited to 'system')
-rw-r--r-- | system/helpers/date_helper.php | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 9637e26ce..6686089c6 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -121,22 +121,20 @@ if ( ! function_exists('standard_date')) * @param int Unix timestamp * @return string */ - function standard_date($fmt = 'DATE_RFC822', $time = '') + function standard_date($fmt = 'DATE_RFC822', $time = NULL) { - $formats = array( - 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%P', - 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC', - 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%P', - 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', - 'DATE_RFC850' => '%l, %d-%M-%y %H:%i:%s UTC', - 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O', - 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_RFC2822' => '%r', - 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%P' - ); - - return isset($formats[$fmt]) ? mdate($formats[$fmt], $time) : FALSE; + if (empty($time)) + { + $time = now(); + } + + // Procedural style pre-defined constants from the DateTime extension + if (strpos($fmt, 'DATE_') !== 0 OR defined($fmt) === FALSE) + { + return FALSE; + } + + return date(constant($fmt), $time); } } |