Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove work-around for bug #81458 #2503

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ jobs:

- name: Install locales
run: |
sudo apt-get update && sudo apt-get install tzdata locales -y && sudo locale-gen fr_FR.UTF-8 sr_ME.UTF-8 ar_AE.UTF-8 zh_TW.UTF-8 zh_CN.UTF-8 yo_NG.UTF-8 en_US.UTF-8
sudo apt-get update || apt --fix-broken install || echo 'Apt failure ignored'
sudo apt-get install tzdata locales -y && sudo locale-gen fr_FR.UTF-8 sr_ME.UTF-8 ar_AE.UTF-8 zh_TW.UTF-8 zh_CN.UTF-8 yo_NG.UTF-8 en_US.UTF-8 || echo 'Apt failure ignored'

- name: Setup Memcached
if: matrix.laravel
Expand Down
17 changes: 2 additions & 15 deletions src/Carbon/Traits/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function diffInWeeks($date = null, $absolute = true)
*/
public function diffInDays($date = null, $absolute = true)
{
return $this->getIntervalDayDiff($this->diff($this->resolveCarbon($date), $absolute));
return (int) $this->diff($this->resolveCarbon($date), $absolute)->format('%r%a');
}

/**
Expand Down Expand Up @@ -518,7 +518,7 @@ public function floatDiffInDays($date = null, $absolute = true)
return $hoursDiff / static::HOURS_PER_DAY;
}

$daysDiff = $this->getIntervalDayDiff($interval);
$daysDiff = (int) $interval->format('%r%a');

return $daysDiff + fmod($hoursDiff, static::HOURS_PER_DAY) / static::HOURS_PER_DAY;
}
Expand Down Expand Up @@ -1149,17 +1149,4 @@ public function calendar($referenceTime = null, array $formats = [])

return $this->isoFormat((string) $format);
}

private function getIntervalDayDiff(DateInterval $interval): int
{
$daysDiff = (int) $interval->format('%r%a');

// Work around PHP 8.1 regression (see https://bugs.php.net/bug.php?id=81458)
if ($daysDiff === 0) {
$daysDiff = ($interval->invert ? -1 : 1) *
($interval->y * static::DAYS_PER_YEAR + $interval->m * 30 + $interval->d);
}

return $daysDiff;
}
}