hughgrigg / php-business-time

Business time logic for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method BusinessTime::diffBusiness returns zero if "start date" is greater than "end date" and $absolute = false

garimpeirodouniverso opened this issue · comments

I tried to get the difference between two dates using the BusinessTime::diffBusiness method, in a fashion that $this is a date greater than $time, and also I'm using $absolute = false (i.e. I expect that the method will return a negative interval in seconds).

While debugging I checked that BusinessTime::diffInBusinessTime is returning the correct negative number, but upon calling Interval::seconds (within diffBusiness) then this number goes to the constructor of CarbonInterval and it ends up zeroing the number.

@garimpeirodouniverso #56

From the PR description there:

DateInterval seems to handle negatives quite weirdly. E.g. the CarbonInterval::inMinutes() method always returns positive. This does make sense in one way, as an interval is in some sense always a positive number.

This PR makes it work a little better than previously, as it was defaulting to 0 for negative intervals.