PHP Business Time library v1.0.0

I’ve just released v1.0.0 of my PHP Business Time library. I made this to solve my own problem that I had building my 3D pop-up card shop – calculating estimated delivery dates based on business time constraints.

It would have been simpler to just solve the exact use case I had (probably hard-coding timings and combining that with retrieving holidays from a remote source), but I thought it would be fun to generalise it and make it into a separate library.

PHP Business Time extends the Carbon date- time library, which makes it quite intuitive to use as it behaves in the same way. For example, you get methods like addBusinessDays() and diffInBusinessDays().

I tried to make the library as adaptable as possible by allowing users to specify their own business time rules. The library has a reasonable default of weekdays 9am to 5pm, but you can take it quite far with configurable constraints, for example:

<?php

$businessTime->setBusinessTimeConstraints(
    (new BusinessTime\Constraint\BetweenHoursOfDay(10, 18))->except(
        new BusinessTime\Constraint\BetweenTimesOfDay('13:00', '14:00')
    ), // 9-6 every day, with an hour for lunch.
    (new BusinessTime\Constraint\WeekDays())->except(
        new BusinessTime\Constraint\WeekDays('Thursday')
    ), // Week days, but let's take Thursdays off.
    new BusinessTime\Constraint\BetweenMonthsOfYear('January', 'November'),
    // No-one does any work in December anyway.
    new BusinessTime\Constraint\Composite\Not(
        new BusinessTime\Constraint\DaysOfYear('August 23rd', 'October 20th')
    ) // Why not take off your birthday and wedding anniversary?
);

It can then perform your business time calculations based on those rules. So far there is support for:

I might add more features as I discover the need for them.


Tech mentioned