briannesbitt / Carbon

A simple PHP API extension for DateTime.
https://carbon.nesbot.com/
MIT License
16.58k stars 1.28k forks source link

`CarbonInterval->forHumans` not working as expected on empty intervals #2233

Closed shengslogar closed 4 years ago

shengslogar commented 4 years ago

Greetings!

I encountered an issue with the following code:

echo Carbon\CarbonInterval::seconds(0)->forHumans();

Carbon version: 2.41.5

PHP version: 7.4.5

I expected to get:

"0 seconds"

But I actually get:

"1 second"

Carbon\CarbonInterval::seconds(>=1)->forHumans() outputs as expected.

Appreciate all your work on this project.

SS

kylekatarnls commented 4 years ago

Hello,

Please check the second example of the "Difference for humans" chapter, you need to disable the NO_ZERO_DIFF option using:

echo CarbonInterval::seconds(0)->forHumans(['options' => 0]);

Thanks.

shengslogar commented 4 years ago

Ah, thank you!