summaryrefslogtreecommitdiffstats
path: root/system/helpers/date_helper.php
diff options
context:
space:
mode:
authorGreg Aker <greg@gregaker.net>2011-12-25 08:44:33 +0100
committerGreg Aker <greg@gregaker.net>2011-12-25 08:44:33 +0100
commitef38f0a6d83025fbd99ace5ec60311acfe9121c4 (patch)
tree1728bc5df9412d8eccc2919bf3cd3f6bbe6a52d0 /system/helpers/date_helper.php
parentd90e1a0fb541ee94459a20cf8b0726aebaec9692 (diff)
parenta96ade374f28cdae97036fc253fd8b2a0e8dc81a (diff)
Merge branch 'develop' into feature/unit-tests
Diffstat (limited to 'system/helpers/date_helper.php')
-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 07e3c1458..b0d79bea5 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)
);
@@ -182,15 +182,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)
{
@@ -199,7 +199,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);
@@ -316,13 +316,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)
);
}
@@ -495,17 +495,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;
}
}
@@ -518,7 +518,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)
@@ -526,7 +526,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))
{
@@ -534,47 +534,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));
}
@@ -689,9 +689,9 @@ if ( ! function_exists('timezones'))
{
return $zones;
}
-
+
$tz = ($tz == 'GMT') ? 'UTC' : $tz;
-
+
return ( ! isset($zones[$tz])) ? 0 : $zones[$tz];
}
}