summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2011-12-20 14:08:09 +0100
committerAndrey Andreev <narf@bofh.bg>2011-12-20 14:08:09 +0100
commit072ad622583f79967ed9ab8269911c6700a95a2f (patch)
tree2fc7d768eb364846c1bbd6623696fe4cb85c500a /system/helpers
parent4eea9895e8ced75a1099c56215c09773de94b92c (diff)
parentfec2f59721af5721ede0d2b60075910a6b646c03 (diff)
Merge remote-tracking branch 'upstream/develop' into develop
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/date_helper.php70
1 files changed, 35 insertions, 35 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index 8c92fdc89..49dbdbeb3 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -5,9 +5,9 @@
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -96,14 +96,14 @@ if ( ! function_exists('mdate'))
{
if ($datestr == '')
{
- return '';
+ return '';
}
$time = ($time == '') ? now() : $time;
$datestr = str_replace(
- '%\\',
- '',
+ '%\\',
+ '',
preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)
);
@@ -181,15 +181,15 @@ if ( ! function_exists('timespan'))
$seconds = ($time <= $seconds) ? 1 : $time - $seconds;
$str = '';
- $years = floor($seconds / 31536000);
+ $years = floor($seconds / 31557600);
if ($years > 0)
{
$str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', ';
}
- $seconds -= $years * 31536000;
- $months = floor($seconds / 2628000);
+ $seconds -= $years * 31557600;
+ $months = floor($seconds / 2629743);
if ($years > 0 OR $months > 0)
{
@@ -198,7 +198,7 @@ if ( ! function_exists('timespan'))
$str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', ';
}
- $seconds -= $months * 2628000;
+ $seconds -= $months * 2629743;
}
$weeks = floor($seconds / 604800);
@@ -315,13 +315,13 @@ if ( ! function_exists('local_to_gmt'))
{
$time = time();
}
-
+
return mktime(
- gmdate("H", $time),
- gmdate("i", $time),
- gmdate("s", $time),
- gmdate("m", $time),
- gmdate("d", $time),
+ gmdate("H", $time),
+ gmdate("i", $time),
+ gmdate("s", $time),
+ gmdate("m", $time),
+ gmdate("d", $time),
gmdate("Y", $time)
);
}
@@ -494,17 +494,17 @@ if ( ! function_exists('human_to_unix'))
if (substr($ampm, 0, 1) == 'p' AND $hour < 12)
{
- $hour = $hour + 12;
+ $hour = $hour + 12;
}
if (substr($ampm, 0, 1) == 'a' AND $hour == 12)
{
$hour = '00';
}
-
+
if (strlen($hour) == 1)
{
- $hour = '0'.$hour;
+ $hour = '0'.$hour;
}
}
@@ -517,7 +517,7 @@ if ( ! function_exists('human_to_unix'))
/**
* Turns many "reasonably-date-like" strings into something
* that is actually useful. This only works for dates after unix epoch.
- *
+ *
* @access public
* @param string The terribly formatted date-like string
* @param string Date format to return (same as php date function)
@@ -525,7 +525,7 @@ if ( ! function_exists('human_to_unix'))
*/
if ( ! function_exists('nice_date'))
{
- function nice_date($bad_date = '', $format = FALSE)
+ function nice_date($bad_date = '', $format = FALSE)
{
if (empty($bad_date))
{
@@ -533,47 +533,47 @@ if ( ! function_exists('nice_date'))
}
// Date like: YYYYMM
- if (preg_match('/^\d{6}$/', $bad_date))
+ if (preg_match('/^\d{6}$/', $bad_date))
{
- if (in_array(substr($bad_date, 0, 2),array('19', '20')))
+ if (in_array(substr($bad_date, 0, 2),array('19', '20')))
{
$year = substr($bad_date, 0, 4);
$month = substr($bad_date, 4, 2);
- }
- else
+ }
+ else
{
$month = substr($bad_date, 0, 2);
$year = substr($bad_date, 2, 4);
}
-
+
return date($format, strtotime($year . '-' . $month . '-01'));
}
-
+
// Date Like: YYYYMMDD
- if (preg_match('/^\d{8}$/',$bad_date))
+ if (preg_match('/^\d{8}$/',$bad_date))
{
$month = substr($bad_date, 0, 2);
$day = substr($bad_date, 2, 2);
$year = substr($bad_date, 4, 4);
-
+
return date($format, strtotime($month . '/01/' . $year));
}
-
+
// Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between)
if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/',$bad_date))
- {
+ {
list($m, $d, $y) = explode('-', $bad_date);
return date($format, strtotime("{$y}-{$m}-{$d}"));
}
-
+
// Any other kind of string, when converted into UNIX time,
// produces "0 seconds after epoc..." is probably bad...
// return "Invalid Date".
if (date('U', strtotime($bad_date)) == '0')
- {
+ {
return "Invalid Date";
}
-
+
// It's probably a valid-ish date format already
return date($format, strtotime($bad_date));
}
@@ -688,9 +688,9 @@ if ( ! function_exists('timezones'))
{
return $zones;
}
-
+
$tz = ($tz == 'GMT') ? 'UTC' : $tz;
-
+
return ( ! isset($zones[$tz])) ? 0 : $zones[$tz];
}
}