summaryrefslogtreecommitdiffstats
path: root/system/helpers/date_helper.php
diff options
context:
space:
mode:
authorDiederikLascaris <info@runesa.nl>2017-01-22 21:45:15 +0100
committerDiederikLascaris <info@runesa.nl>2017-01-22 21:45:15 +0100
commit312efeba32d532878c536fd28e75f39d61a9dade (patch)
tree71ae4aaca33a9d34a789d6d375acd2594160123a /system/helpers/date_helper.php
parent947f1a06093a52a32b703ee795e52c22cd66363a (diff)
parent44c7af639ac1726780b64fb5a6cb6fca2df8b651 (diff)
Merge branch 'develop' of git://github.com/bcit-ci/CodeIgniter into develop
Diffstat (limited to 'system/helpers/date_helper.php')
-rw-r--r--system/helpers/date_helper.php134
1 files changed, 20 insertions, 114 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index c9b71c30f..799c9f6d2 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -6,7 +6,7 @@
*
* This content is released under the MIT License (MIT)
*
- * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
+ * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -28,10 +28,10 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
- * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
+ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
- * @link http://codeigniter.com
+ * @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
@@ -44,7 +44,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* @subpackage Helpers
* @category Helpers
* @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/helpers/date_helper.html
+ * @link https://codeigniter.com/user_guide/helpers/date_helper.html
*/
// ------------------------------------------------------------------------
@@ -122,46 +122,6 @@ if ( ! function_exists('mdate'))
// ------------------------------------------------------------------------
-if ( ! function_exists('standard_date'))
-{
- /**
- * 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().
- *
- * @todo Remove in version 3.1+.
- * @deprecated 3.0.0 Use PHP's native date() instead.
- * @link http://www.php.net/manual/en/class.datetime.php#datetime.constants.types
- *
- * @example date(DATE_RFC822, now()); // default
- * @example date(DATE_W3C, $time); // a different format and time
- *
- * @param string $fmt = 'DATE_RFC822' the chosen format
- * @param int $time = NULL Unix timestamp
- * @return string
- */
- function standard_date($fmt = 'DATE_RFC822', $time = NULL)
- {
- 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);
- }
-}
-
-// ------------------------------------------------------------------------
-
if ( ! function_exists('timespan'))
{
/**
@@ -496,6 +456,7 @@ if ( ! function_exists('nice_date'))
* Turns many "reasonably-date-like" strings into something
* that is actually useful. This only works for dates after unix epoch.
*
+ * @deprecated 3.1.3 Use DateTime::createFromFormat($input_format, $input)->format($output_format);
* @param string The terribly formatted date-like string
* @param string Date format to return (same as php date function)
* @return string
@@ -529,9 +490,9 @@ if ( ! function_exists('nice_date'))
}
// Date Like: YYYYMMDD
- if (preg_match('/^(\d{2})\d{2}(\d{4})$/i', $bad_date, $matches))
+ if (preg_match('/^\d{8}$/i', $bad_date, $matches))
{
- return date($format, strtotime($matches[1].'/01/'.$matches[2]));
+ return DateTime::createFromFormat('Ymd', $bad_date)->format($format);
}
// Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between)
@@ -707,87 +668,32 @@ if ( ! function_exists('date_range'))
$range = array();
- /* NOTE: Even though the DateTime object has many useful features, it appears that
- * it doesn't always handle properly timezones, when timestamps are passed
- * directly to its constructor. Neither of the following gave proper results:
- *
- * new DateTime('<timestamp>')
- * new DateTime('<timestamp>', '<timezone>')
- *
- * --- available in PHP 5.3:
- *
- * DateTime::createFromFormat('<format>', '<timestamp>')
- * DateTime::createFromFormat('<format>', '<timestamp>', '<timezone')
- *
- * ... so we'll have to set the timestamp after the object is instantiated.
- * Furthermore, in PHP 5.3 we can use DateTime::setTimestamp() to do that and
- * given that we have UNIX timestamps - we should use it.
- */
$from = new DateTime();
+ $from->setTimestamp($unix_start);
- if (is_php('5.3'))
- {
- $from->setTimestamp($unix_start);
- if ($is_unix)
- {
- $arg = new DateTime();
- $arg->setTimestamp($mixed);
- }
- else
- {
- $arg = (int) $mixed;
- }
-
- $period = new DatePeriod($from, new DateInterval('P1D'), $arg);
- foreach ($period as $date)
- {
- $range[] = $date->format($format);
- }
-
- /* If a period end date was passed to the DatePeriod constructor, it might not
- * be in our results. Not sure if this is a bug or it's just possible because
- * the end date might actually be less than 24 hours away from the previously
- * generated DateTime object, but either way - we have to append it manually.
- */
- if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format))
- {
- $range[] = $arg->format($format);
- }
-
- return $range;
- }
-
- $from->setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start));
- $from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start));
if ($is_unix)
{
$arg = new DateTime();
- $arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed));
- $arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed));
+ $arg->setTimestamp($mixed);
}
else
{
$arg = (int) $mixed;
}
- $range[] = $from->format($format);
- if (is_int($arg)) // Day intervals
+ $period = new DatePeriod($from, new DateInterval('P1D'), $arg);
+ foreach ($period as $date)
{
- do
- {
- $from->modify('+1 day');
- $range[] = $from->format($format);
- }
- while (--$arg > 0);
+ $range[] = $date->format($format);
}
- else // end date UNIX timestamp
- {
- for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format('Ymd') < $end_check; $from->modify('+1 day'))
- {
- $range[] = $from->format($format);
- }
- // Our loop only appended dates prior to our end date
+ /* If a period end date was passed to the DatePeriod constructor, it might not
+ * be in our results. Not sure if this is a bug or it's just possible because
+ * the end date might actually be less than 24 hours away from the previously
+ * generated DateTime object, but either way - we have to append it manually.
+ */
+ if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format))
+ {
$range[] = $arg->format($format);
}