Fix #2531
Showing 1 of 2 files from the diff.
src/Carbon/Traits/Difference.php
changed.
Other files ignored by Codecov
tests/Carbon/DiffTest.php
has changed.
@@ -217,7 +217,7 @@
Loading
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,7 +518,7 @@
Loading
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,4 +1149,21 @@
Loading
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('%a'); |
|
1156 | + | $sign = $interval->format('%r') === '-' ? -1 : 1; |
|
1157 | + | ||
1158 | + | if (is_int($interval->days) && |
|
1159 | + | $interval->y === 0 && |
|
1160 | + | $interval->m === 0 && |
|
1161 | + | version_compare(PHP_VERSION, '8.1.0-dev', '<') && |
|
1162 | + | abs($interval->d - $daysDiff) === 1 |
|
1163 | + | ) { |
|
1164 | + | $daysDiff = abs($interval->d); |
|
1165 | + | } |
|
1166 | + | ||
1167 | + | return $daysDiff * $sign; |
|
1168 | + | } |
|
1152 | 1169 | } |
Files | Complexity | Coverage |
---|---|---|
src/Carbon | 2,171 | 100.00% |
Project Totals (886 files) | 2171 | 100.00% |
1659430866
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.