summaryrefslogtreecommitdiffstats
path: root/system/helpers/date_helper.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-20 14:35:50 +0100
committerAndrey Andreev <narf@bofh.bg>2012-03-20 14:35:50 +0100
commit160a4e5628aba8b5e35da784ec87037e133c1f05 (patch)
tree3ceec6e888a078bfe86ebfefe2e126f9b23f384f /system/helpers/date_helper.php
parentad97736d8249240cba802d33a24b7b11e02488cf (diff)
parent820999cb0d82c80d6dc5dde133568812c8113e29 (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 ead0d1723..e734d6a57 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -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);
}
}
@@ -827,4 +834,4 @@ if ( ! function_exists('date_range'))
}
/* End of file date_helper.php */
-/* Location: ./system/helpers/date_helper.php */
+/* Location: ./system/helpers/date_helper.php */ \ No newline at end of file