我有一个生成日期对矩阵的函数。 具体来说,它需要两个日期并将31天范围添加到数组中,所以粗略地看起来像: 我正在使用递归函数来执行此操作: p>
现在,当我调试调用此函数的测试时 功能,似乎工作正常: p>
然而,测试大致如下 : p>
失败,因为 [[date,date + 31],[date,date + 31],...] code> p>
public function getBatchDates(Carbon $ start,Carbon $ end, array $ arr){
$ setEnd = Carbon :: createFromTimestamp($ start-> getTimestamp()) - > addDays(31);
if($ setEnd-> greaterThanOrEqualTo($ end)){
$ setEnd = $ end;
array_push($ arr,array($ start,$ setEnd));
return;
}
array_push($ arr,array($ start,$ setEnd)); \ n
$ this-> getBatchDates($ setEnd,$ end,$ arr);
}
code> pre>
<鳕鱼 e> $ array = array();
getBatchDates(new Carbon(“2015年12月的第一天”),Carbon :: now(),$ array);
$ this-&gt; assertNotNull($ array);
$ this-&gt; assertGreaterThan(0,sizeof($ array));
code> pre>
$ array code>是 长度为0的。 是否有一些我缺少的东西,调试器使它看起来像是有效的。 p>
div>
I've got a function that generates a matrix of date pairs. specifically, it takes two dates and adds the 31 day ranges to an array, so roughly, it would look like: [[date, date+31], [date, date+31], ...]
I'm using a recursive function to do it:
public function getBatchDates(Carbon $start, Carbon $end, array $arr) {
$setEnd = Carbon::createFromTimestamp($start->getTimestamp())->addDays(31);
if($setEnd->greaterThanOrEqualTo($end)) {
$setEnd = $end;
array_push($arr, array($start, $setEnd));
return;
}
array_push($arr, array($start, $setEnd));
$this->getBatchDates($setEnd, $end, $arr);
}
Now, when I debug the test that calls this function, it seems to work correctly:
However, the test, which is roughly as follows:
$array = array();
getBatchDates(new Carbon("first day of December 2015"),Carbon::now(), $array);
$this->assertNotNull($array);
$this->assertGreaterThan(0, sizeof($array));
It fails, because the $array
is 0-length. Is there something I'm missing, the debugger makes it look like things are working.