summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-07-28 15:40:12 +0200
committerAndrey Andreev <narf@devilix.net>2016-07-28 15:40:12 +0200
commita838279625becfba98ccb7635d35c67297129c42 (patch)
tree6ddf87407a88b84dc90503d5e7ac68c40cd07d66 /system/helpers
parent1748567f5442409d6a8c1e795f56599caff8296e (diff)
Remove dead code written for PHP 5.2
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/date_helper.php79
1 files changed, 12 insertions, 67 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index c43209f05..5f1fcf07e 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -707,87 +707,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);
}