summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-07-05 15:31:12 +0200
committerAndrey Andreev <narf@bofh.bg>2012-07-05 15:31:12 +0200
commit92d18a7b6c46eadc9db58ca60ffce3980e2313ff (patch)
treeb0a869a5312279d65c3e920ffbf0b32344ab1d0f /system/helpers
parentd66872ae5d7cd4d2b531251a9c63528e81af3322 (diff)
parent7ca36131d881d3f83a86d824263d4abd65439e12 (diff)
Merge upstream branch
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/array_helper.php6
-rw-r--r--system/helpers/date_helper.php41
2 files changed, 29 insertions, 18 deletions
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php
index 216f12e56..ed2fe3c4a 100644
--- a/system/helpers/array_helper.php
+++ b/system/helpers/array_helper.php
@@ -43,7 +43,7 @@ if ( ! function_exists('element'))
* Element
*
* Lets you determine whether an array index is set and whether it has a value.
- * If the element is empty it returns FALSE (or whatever you specify as the default value.)
+ * If the element is empty it returns NULL (or whatever you specify as the default value.)
*
* @param string
* @param array
@@ -52,7 +52,7 @@ if ( ! function_exists('element'))
*/
function element($item, $array, $default = NULL)
{
- return empty($array[$item]) ? $default : $array[$item];
+ return array_key_exists($item, $array) ? $array[$item] : $default;
}
}
@@ -95,7 +95,7 @@ if ( ! function_exists('elements'))
foreach ($items as $item)
{
- $return[$item] = isset($array[$item]) ? $array[$item] : $default;
+ $return[$item] = array_key_exists($item, $array) ? $array[$item] : $default;
}
return $return;
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);
}
}