Permalink
Browse files

Fix DatePeriod to not return the same instance all the time

Summary:
- This was just broken
- PHP does the right thing so we should too

Reviewed By: paulbiss

Differential Revision: D8544375

fbshipit-source-id: 7cb0b7554ef94290cf034309a10eaf18c3ae5ea0
  • Loading branch information...
WizKid authored and hhvm-bot committed Jul 12, 2018
1 parent c67bcfd commit 80208215c7dc479f16e616d3ffd4a913944c3ef1
@@ -91,7 +91,7 @@ private function __constructImpl(
}
function current() {
return $this->current;
return clone $this->current;
}
function rewind() {
@@ -110,8 +110,8 @@ function key() {
function next() {
if ($this->valid()) {
// Assign in case it's a DateTimeImmutable
$this->current = $this->current->add($this->interval);
$current = clone $this->current;
$this->current = $current->add($this->interval);
$this->iterKey++;
}
}
@@ -0,0 +1,17 @@
<?php
$begin = new DateTime( '2012-08-01' );
$end = new DateTime( '2012-08-31' );
$end = $end->modify( '+1 day' );
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
$v = array();
foreach($daterange as $date){
echo $date->format("Ymd") . "\n";
$v[] = $date;
}
foreach ($v as $date) {
echo $date->format("Ymd") . "\n";
}
@@ -0,0 +1,62 @@
20120801
20120802
20120803
20120804
20120805
20120806
20120807
20120808
20120809
20120810
20120811
20120812
20120813
20120814
20120815
20120816
20120817
20120818
20120819
20120820
20120821
20120822
20120823
20120824
20120825
20120826
20120827
20120828
20120829
20120830
20120831
20120801
20120802
20120803
20120804
20120805
20120806
20120807
20120808
20120809
20120810
20120811
20120812
20120813
20120814
20120815
20120816
20120817
20120818
20120819
20120820
20120821
20120822
20120823
20120824
20120825
20120826
20120827
20120828
20120829
20120830
20120831

0 comments on commit 8020821

Please sign in to comment.