League\Period\Period::diff PHP Method

diff() public method

Returns an array containing the difference expressed as Period objects The array will:
  • be empty if both objects have the same datepoints
  • contain one Period object if both objects share one datepoint
  • contain two Period objects if both objects share no datepoint
public diff ( Period $period ) : Period[]
$period Period
return Period[]
    public function diff(Period $period)
    {
        if (!$this->overlaps($period)) {
            throw new LogicException('Both Period objects should overlaps');
        }
        $res = [static::createFromDatepoints($this->startDate, $period->getStartDate()), static::createFromDatepoints($this->endDate, $period->getEndDate())];
        $filter = function (Period $period) {
            return $period->getStartDate() != $period->getEndDate();
        };
        return array_values(array_filter($res, $filter));
    }