diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-07-05 15:31:12 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-07-05 15:31:12 +0200 |
commit | 92d18a7b6c46eadc9db58ca60ffce3980e2313ff (patch) | |
tree | b0a869a5312279d65c3e920ffbf0b32344ab1d0f /system/helpers/date_helper.php | |
parent | d66872ae5d7cd4d2b531251a9c63528e81af3322 (diff) | |
parent | 7ca36131d881d3f83a86d824263d4abd65439e12 (diff) |
Merge upstream branch
Diffstat (limited to 'system/helpers/date_helper.php')
-rw-r--r-- | system/helpers/date_helper.php | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index fc790c585..a45b3d7ac 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -117,26 +117,37 @@ if ( ! function_exists('standard_date')) * * Returns a date formatted according to the submitted standard. * + * As of PHP 5.2, the DateTime extension provides constants that + * serve for the exact same purpose and are used with date(). + * Due to that, this function is DEPRECATED and should be removed + * in CodeIgniter 3.1+. + * + * Here are two examples of how you should replace it: + * + * date(DATE_RFC822, now()); // default + * date(DATE_W3C, $time); // a different format and time + * + * Reference: http://www.php.net/manual/en/class.datetime.php#datetime.constants.types + * + * @deprecated * @param string the chosen format * @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%O', - 'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC', - 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%O', - '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' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%O' - ); - - 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); } } |