src/Carbon/Traits/Difference.php
changed.
Other files ignored by Codecov
tests/Carbon/TestingAidsTest.php
has changed.
217 | 217 | */ |
|
218 | 218 | public function diffInDays($date = null, $absolute = true) |
|
219 | 219 | { |
|
220 | - | return (int) $this->diff($this->resolveCarbon($date), $absolute)->format('%r%a'); |
|
220 | + | return $this->getIntervalDayDiff($this->diff($this->resolveCarbon($date), $absolute)); |
|
221 | 221 | } |
|
222 | 222 | ||
223 | 223 | /** |
518 | 518 | return $hoursDiff / static::HOURS_PER_DAY; |
|
519 | 519 | } |
|
520 | 520 | ||
521 | - | $daysDiff = (int) $interval->format('%r%a'); |
|
521 | + | $daysDiff = $this->getIntervalDayDiff($interval); |
|
522 | 522 | ||
523 | 523 | return $daysDiff + fmod($hoursDiff, static::HOURS_PER_DAY) / static::HOURS_PER_DAY; |
|
524 | 524 | } |
1149 | 1149 | ||
1150 | 1150 | return $this->isoFormat((string) $format); |
|
1151 | 1151 | } |
|
1152 | + | ||
1153 | + | private function getIntervalDayDiff(DateInterval $interval): int |
|
1154 | + | { |
|
1155 | + | $daysDiff = (int) $interval->format('%r%a'); |
|
1156 | + | ||
1157 | + | // Work around PHP 8.1 regression (see https://bugs.php.net/bug.php?id=81458) |
|
1158 | + | if ($daysDiff === 0) { |
|
1159 | + | $daysDiff = ($interval->invert ? -1 : 1) * |
|
1160 | + | ($interval->y * static::DAYS_PER_YEAR + $interval->m * 30 + $interval->d); |
|
1161 | + | } |
|
1162 | + | ||
1163 | + | return $daysDiff; |
|
1164 | + | } |
|
1152 | 1165 | } |
Files | Complexity | Coverage |
---|---|---|
src/Carbon | 2,161 | 100.00% |
Project Totals (886 files) | 2161 | 100.00% |