有一天,我有以下功能的笨功能:功能的DatePeriod迭代缺少第二个函数调用
/**
* Returns Days within a period of time defined by two DateTime objects
*
*
* @param $start DateTime
* @param $end DateTime
* @param $points
*
* $return['days'][x]
*/
public function getDaysInRange(DateTime $start,DateTime $end){
$this->debug(memory_get_usage()/1024,"Memory Usage in KB");
$this->debug(memory_get_peak_usage()/1024,"Peak Memory Usage in KB");
$this->debug(memory_get_peak_usage(true)/1024,"Real Peak Memory Usage in KB");
$interval = new DateInterval('P1D'); // 1Day Interval
$startC= clone $start;
$startC->setTime(0,0,0);
$endC = clone $end;
$endC->setTime(0,0,0);
// Workaround because last day of period is not in Iterator
$endC->add($interval);
$this->debug($startC,"Get Days in Range Start");
$this->debug($endC,"Get Days in Range End");
$daterange = new DatePeriod($startC, $interval,$endC);
$return = array('days' => array());
foreach($daterange as $date){
$this->debug($date->format("Y-m-d"),"Single Day in Daterange");
$return['days'][] = $date->format("Y-m-d");
}
$this->debug($return,"Return of getDays in Range");
return $return;
}
当我调用该函数2个不同的datetime对象倍。
[start] => DateTime Object
(
[date] => 2014-03-01 00:00:00
[timezone_type] => 1
[timezone] => +00:00
)
[end] => DateTime Object
(
[date] => 2014-03-31 00:00:00
[timezone_type] => 1
[timezone] => +00:00
)
[start] => DateTime Object
(
[date] => 2014-03-01 00:00:00
[timezone_type] => 1
[timezone] => +00:00
)
[end] => DateTime Object
(
[date] => 2014-03-31 00:00:00
[timezone_type] => 1
[timezone] => +00:00
)
从时间戳创建:
$begin = DateTime::createFromFormat('U', $filter['start'], new DateTimeZone('UTC'));
$end = DateTime::createFromFormat('U', $filter['end'], new DateTimeZone('UTC'));
的第一次调用返回正确:
(
[days] => Array
(
[0] => 2014-03-01
[1] => 2014-03-02
[2] => 2014-03-03
[3] => 2014-03-04
[4] => 2014-03-05
[5] => 2014-03-06
[6] => 2014-03-07
[7] => 2014-03-08
[8] => 2014-03-09
[9] => 2014-03-10
[10] => 2014-03-11
[11] => 2014-03-12
[12] => 2014-03-13
[13] => 2014-03-14
[14] => 2014-03-15
[15] => 2014-03-16
[16] => 2014-03-17
[17] => 2014-03-18
[18] => 2014-03-19
[19] => 2014-03-20
[20] => 2014-03-21
[21] => 2014-03-22
[22] => 2014-03-23
[23] => 2014-03-24
[24] => 2014-03-25
[25] => 2014-03-26
[26] => 2014-03-27
[27] => 2014-03-28
[28] => 2014-03-29
[29] => 2014-03-30
[30] => 2014-03-31
)
)
第二个呼叫retruns以下,滞后于 “2014年3月25日”
(
[days] => Array
(
[0] => 2014-03-01
[1] => 2014-03-02
[2] => 2014-03-03
[3] => 2014-03-04
[4] => 2014-03-05
[5] => 2014-03-06
[6] => 2014-03-07
[7] => 2014-03-08
[8] => 2014-03-09
[9] => 2014-03-10
[10] => 2014-03-11
[11] => 2014-03-12
[12] => 2014-03-13
[13] => 2014-03-14
[14] => 2014-03-15
[15] => 2014-03-16
[16] => 2014-03-17
[17] => 2014-03-18
[18] => 2014-03-19
[19] => 2014-03-20
[20] => 2014-03-21
[21] => 2014-03-22
[22] => 2014-03-23
[23] => 2014-03-24
[24] => 2014-03-26
[25] => 2014-03-27
[26] => 2014-03-28
[27] => 2014-03-29
[28] => 2014-03-30
[29] => 2014-03-31
)
)
我首先想到了sid eeffects。我错过了吗?
在php的bugtracker没有具体到我的问题,但一些其他有关DatePeriod的奇怪行为的报告。在服务器上运行一个很老的PHP 5.3.10。
在用较新版本的php重现bug之前,我试图在Codeigniter之外重现它。外面是在各种星座工作。见:http://pastebin.com/FgPTSMEz
所以我想在codeigniter环境中可能会造成内存使用量过大,这可能会导致错误。但codeigniter内部的内存使用量仅为4-5 MB。我在独立的测试文件中复制了5 MB的文本文件。
目前我不知道问题是什么。
'2014-03-25'在你的第一个输出缺失,以及(除非这是一个复制和粘贴错误)。 – CBroe
我敢打赌,这是与DST相关的。时钟在27日在英国发生了变化。 – Jim
@CBroe是c&p错误 – Dukeatcoding