Spatie\Analytics\Exceptions\InvalidPeriod::startDateCannotBeAfterEndDate PHP Method

startDateCannotBeAfterEndDate() public static method

public static startDateCannotBeAfterEndDate ( DateTime $startDate, DateTime $endDate )
$startDate DateTime
$endDate DateTime
    public static function startDateCannotBeAfterEndDate(DateTime $startDate, DateTime $endDate)
    {
        return new static("Start date `{$startDate->format('Y-m-d')}` cannot be after end date `{$endDate->format('Y-m-d')}`.");
    }

Usage Example

Example #1
0
 public function __construct(DateTime $startDate, DateTime $endDate)
 {
     if ($startDate > $endDate) {
         throw InvalidPeriod::startDateCannotBeAfterEndDate($startDate, $endDate);
     }
     $this->startDate = $startDate;
     $this->endDate = $endDate;
 }