summaryrefslogtreecommitdiffstats
path: root/system/helpers/date_helper.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-20 15:59:04 +0100
committerAndrey Andreev <narf@bofh.bg>2012-03-20 15:59:04 +0100
commit817164d822ce5dc1159ddc3e8fad2fa094dfc5ea (patch)
tree125069e2089d0e0ee3b8337b7acac6050ca1e045 /system/helpers/date_helper.php
parent4b4363871256df9009bb4245def8f89420331cfd (diff)
parent8480f7c35af9aacaf2ebee43677ff1d31a5cce13 (diff)
Merge upstream branch
Diffstat (limited to 'system/helpers/date_helper.php')
-rw-r--r--system/helpers/date_helper.php49
1 files changed, 28 insertions, 21 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index 9e58d8630..d54553292 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -128,15 +128,16 @@ if ( ! function_exists('standard_date'))
function standard_date($fmt = 'DATE_RFC822', $time = '')
{
$formats = array(
- 'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q',
+ '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%Q',
+ '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%Q'
+ 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%O'
);
if ( ! isset($formats[$fmt]))
@@ -159,11 +160,12 @@ if ( ! function_exists('standard_date'))
* @access public
* @param integer a number of seconds
* @param integer Unix timestamp
- * @return integer
+ * @param integer a number of display units
+ * @return string
*/
if ( ! function_exists('timespan'))
{
- function timespan($seconds = 1, $time = '')
+ function timespan($seconds = 1, $time = '', $units = 7)
{
$CI =& get_instance();
$CI->lang->load('date');
@@ -178,24 +180,29 @@ if ( ! function_exists('timespan'))
$time = time();
}
+ if ( ! is_numeric($units))
+ {
+ $units = 7;
+ }
+
$seconds = ($time <= $seconds) ? 1 : $time - $seconds;
- $str = '';
+ $str = array();
$years = floor($seconds / 31557600);
if ($years > 0)
{
- $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', ';
+ $str[] = $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year'));
}
$seconds -= $years * 31557600;
$months = floor($seconds / 2629743);
- if ($years > 0 OR $months > 0)
+ if (count($str) < $units && ($years > 0 OR $months > 0))
{
if ($months > 0)
{
- $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', ';
+ $str[] = $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month'));
}
$seconds -= $months * 2629743;
@@ -203,11 +210,11 @@ if ( ! function_exists('timespan'))
$weeks = floor($seconds / 604800);
- if ($years > 0 OR $months > 0 OR $weeks > 0)
+ if (count($str) < $units && ($years > 0 OR $months > 0 OR $weeks > 0))
{
if ($weeks > 0)
{
- $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', ';
+ $str[] = $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week'));
}
$seconds -= $weeks * 604800;
@@ -215,11 +222,11 @@ if ( ! function_exists('timespan'))
$days = floor($seconds / 86400);
- if ($months > 0 OR $weeks > 0 OR $days > 0)
+ if (count($str) < $units && ($months > 0 OR $weeks > 0 OR $days > 0))
{
if ($days > 0)
{
- $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', ';
+ $str[] = $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day'));
}
$seconds -= $days * 86400;
@@ -227,11 +234,11 @@ if ( ! function_exists('timespan'))
$hours = floor($seconds / 3600);
- if ($days > 0 OR $hours > 0)
+ if (count($str) < $units && ($days > 0 OR $hours > 0))
{
if ($hours > 0)
{
- $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', ';
+ $str[] = $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour'));
}
$seconds -= $hours * 3600;
@@ -239,22 +246,22 @@ if ( ! function_exists('timespan'))
$minutes = floor($seconds / 60);
- if ($days > 0 OR $hours > 0 OR $minutes > 0)
+ if (count($str) < $units && ($days > 0 OR $hours > 0 OR $minutes > 0))
{
if ($minutes > 0)
{
- $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', ';
+ $str[] = $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute'));
}
$seconds -= $minutes * 60;
}
- if ($str == '')
+ if (count($str) === 0)
{
- $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', ';
+ $str[] = $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second'));
}
- return substr(trim($str), 0, -1);
+ return implode(', ', $str);
}
}