Skip to content

Commit

Permalink
Merge pull request #446 from cakephp/fix-445
Browse files Browse the repository at this point in the history
Fix off by one errors in diffFiltered
  • Loading branch information
othercorey authored Nov 3, 2023
2 parents 96f28dd + cdbb22d commit 03208c1
Show file tree
Hide file tree
Showing 2 changed files with 462 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/Traits/DifferenceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,10 @@ public function diffFiltered(
$end = $this;
$inverse = true;
}
// Hack around DatePeriod not including end values.
// When handling dates we need to convert to a DateTime
// and offset by 1 second.
if ($end instanceof ChronosDate) {
$end = (new Chronos($end))->modify('+1 second');
}

$period = new DatePeriod($start, $ci, $end);
$vals = array_filter(iterator_to_array($period), function (DateTimeInterface $date) use ($callback) {
return $callback(static::instance($date));
return $callback(static::parse($date));
});

$diff = count($vals);
Expand Down
Loading

0 comments on commit 03208c1

Please sign in to comment.