diff options
author | Andrey Andreev <narf@devilix.net> | 2016-08-10 14:26:57 +0200 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2016-08-10 14:26:57 +0200 |
commit | c4bd43432df03e4f4835c7689c8ed722cd2c3020 (patch) | |
tree | 5603166833d78b0581bbe880adb53b6de085719d /system/helpers/date_helper.php | |
parent | 488ad40ba334ca506f07bede97724726eac2b27f (diff) | |
parent | 9180a1264dc536c34e5cc8a0e44bb399a8ba484f (diff) |
Merge branch '3.1-stable' into develop
Diffstat (limited to 'system/helpers/date_helper.php')
-rw-r--r-- | system/helpers/date_helper.php | 79 |
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); } |