Carbon: diffInSeconds broken after PHP 7.2.12 release
Hello,
I encountered an issue with the following code:
$now = Carbon::now();
// some milliseconds pass.
echo Carbon::now()->diffInSeconds($now, false);
Carbon version: 1.34.1 PHP version: 7.2.12
I expected to get:
0
But I actually get:
A much higher number (differs depending on how much milliseconds have passed).
I believe this is because https://bugs.php.net/bug.php?id=77007 was merged for 7.2.12 causing differences between these versions. I’m not sure how this should be solved.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 24 (8 by maintainers)
Commits related to this issue
- Debug #1503 (PHP bug 77007) — committed to kylekatarnls/Carbon by kylekatarnls 6 years ago
- Work-around #1503 — committed to kylekatarnls/Carbon by kylekatarnls 6 years ago
- Work-around #1503 — committed to kylekatarnls/Carbon by kylekatarnls 6 years ago
- Work-around #1503 — committed to kylekatarnls/Carbon by kylekatarnls 6 years ago
- Fix #1503 (PHP bug 77007) handle negative microseconds — committed to kylekatarnls/Carbon by kylekatarnls 6 years ago
- Fix #1503 (PHP bug 77007) handle negative microseconds (#1505) * Fix #1503 (PHP bug 77007) handle negative microseconds — committed to briannesbitt/Carbon by kylekatarnls 6 years ago
- [5.5] Fix cache repository (#26497) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to laravel/framework by driesvints 6 years ago
- [5.6] Fix cache repository (#26496) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to laravel/framework by driesvints 6 years ago
- [5.7] Fix cache repository (#26495) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to laravel/framework by driesvints 6 years ago
- [5.7] Fix cache repository (#26495) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to illuminate/cache by driesvints 6 years ago
- [5.6] Fix cache repository (#26496) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to illuminate/cache by driesvints 6 years ago
- [5.6] Fix cache repository (#26496) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to illuminate/support by driesvints 6 years ago
- [5.5] Fix cache repository (#26497) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to illuminate/cache by driesvints 6 years ago
- [5.5] Fix cache repository (#26497) * Fix a bug with PHP 7.2.12 PHP 7.2.12 broke the way Carbon's diffInSeconds method works. Using diffInRealSeconds instead fixes the problem. See https://gith... — committed to illuminate/support by driesvints 6 years ago
https://bugs.php.net/bug.php?id=77007 is a very big problem for us and the way we handle difference. It clearly can be the root cause.
I’m a bit exhausted of the breaking patches of the PHP DateTime API. I will try to create a work-around.
You may be interested in the following possibilities:
->startOfSecond()
before diff calculation to force a second-rounding.More precise support done in 1.35.0 and 2.5.3. Now to detect faster those breaking patches, I opened an other issue: https://github.com/briannesbitt/Carbon/issues/1511
Opened new ticket on PHP bug tracker: https://bugs.php.net/bug.php?id=77145
You’re welcome, we really appreciate Laravel too ! And I enjoy using it for a lot of my personal projects.