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
[v1.35.0] diffInSeconds() incorrect by 86399 seconds if one date has microseconds #1515
Comments
Further to the above if you do the diff in the other direction, it works as expected... echo $requestTime->diffInSeconds($serverTime, true) // 0 <-- correct
echo $serverTime->diffInSeconds($requestTime, true); // 86399 <-- incorrect |
To give some more context, the This bug only happens when the time being diffed doesn't have microseconds, but the time doing the diffing does have microseconds. |
The above is on a Homestead Vagrant VirtualBox VM. Running the same code on my local machine with So it could be specific to |
Having the same issue, specifically on 7.2.12, not happening on 7.2.10 |
Also not happening on 7.2.11. |
Yes, PHP has a known bug appearing in certains specific versions (PHP create an interval with year = -1, month = 11, days = 29). I thought we found a way, but seems not in all cases. A work-around while we figure it out is to trim microseconds: $requestTime->startOfSecond()->diffInSeconds($serverTime->startOfSecond(), true) |
http://php.net/ChangeLog-7.php#7.2.12
|
Or simplest work-around (often more relevant too), use |
This should fix this case: #1517 waiting for tests to pass in every PHP versions to be sure. |
Hi guys, please retry with 1.35.1. Note: |
Yep $ artisan tinker
Psy Shell v0.9.9 (PHP 7.2.12-1+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> $requestTime = new \Carbon\Carbon('2018-11-14 18:23:12.0 +00:00');
=> Carbon\Carbon @1542219792 {#2980
date: 2018-11-14 18:23:12.0 +00:00,
}
>>> $serverTime = new \Carbon\Carbon('2018-11-14 18:23:12.307628 +00:00');
=> Carbon\Carbon @1542219792 {#2981
date: 2018-11-14 18:23:12.307628 +00:00,
}
>>> $serverTime->diffInSeconds($requestTime);
=> 0
>>> $requestTime->diffInSeconds($serverTime);
=> 0 |
Hello,
I encountered an issue with the following code:
Carbon version: 1.35.0
PHP version:7.2.12-1+ubuntu18.04.1+deb.sury.org+1
I expected to get:
But I actually get:
Obviously this is very close to being 1 day worth of seconds, so something strange appears to be going on somewhere...
Thanks!
The text was updated successfully, but these errors were encountered: