hughgrigg / php-business-time

Business time logic for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Failed to parse time string

cjsfj opened this issue · comments

commented

Here's my business time setup:

$dates = "'2016-10-31', '2016-12-25', '2016-12-26', '2017-03-17', '2017-04-17', '2017-05-01', '2017-06-05', '2017-08-07', '2017-10-30', '2017-12-25', '2017-12-26', '2018-03-19', '2018-04-02', '2018-05-07', '2018-06-04', '2018-08-06', '2018-12-25', '2018-12-26', '2019-01-01'";

$businessTime = new BusinessTime\BusinessTime();
$businessTime->setBusinessTimeConstraints(
        new BusinessTime\Constraint\WeekDays(),
        new BusinessTime\Constraint\BetweenTimesOfDay('08:00', '18:00'),
        new BusinessTime\Constraint\Composite\Not(
            new BusinessTime\Constraint\Dates($dates)
        )
    );

I am getting an Failed to parse time string error on the line setting the Dates:

PHP Fatal error:  Uncaught Exception: DateTime::__construct(): Failed to parse time string ('2016-10-31', '2016-12-25', '2016-12-26', '2017-03-17', '2017-04-17', '2017-05-01', '2017-06-05', '2017-08-07', '2017-10-30', '2017-12-25', '2017-12-26', '2018-03-19', '2018-04-02', '2018-05-07', '2018-06-04', '2018-08-06', '2018-12-25', '2018-12-26', '2019-01-01') at position 0 ('): Unexpected character in /data/www/fbz/vendor/hughgrigg/php-business-time/src/Constraint/Dates.php:31

The examples in the README show that the Date Constraint seems to want the list of dates in this format, but I've tried an array of dates, or an array of DateTime objects, and none worked.

Ultimately, I'm looking for open weekdays from 8am to 6pm, except specific holidays from a list.

Thanks,

CJ

commented

looks like I was just up too late last night.

$dates should be an argument list, not a string. Changing $dates to an array and using the splat operator did the needful.