%PDF- %PDF-
Direktori : /home/graphicd/public_html/vebto/vendor/spatie/laravel-analytics/src/ |
Current File : /home/graphicd/public_html/vebto/vendor/spatie/laravel-analytics/src/Period.php |
<?php namespace Spatie\Analytics; use Carbon\Carbon; use DateTimeInterface; use Spatie\Analytics\Exceptions\InvalidPeriod; class Period { /** @var \DateTimeInterface */ public $startDate; /** @var \DateTimeInterface */ public $endDate; public static function create(DateTimeInterface $startDate, DateTimeInterface $endDate): self { return new static($startDate, $endDate); } public static function days(int $numberOfDays): self { $endDate = Carbon::today(); $startDate = Carbon::today()->subDays($numberOfDays)->startOfDay(); return new static($startDate, $endDate); } public static function months(int $numberOfMonths): self { $endDate = Carbon::today(); $startDate = Carbon::today()->subMonths($numberOfMonths)->startOfDay(); return new static($startDate, $endDate); } public static function years(int $numberOfYears): self { $endDate = Carbon::today(); $startDate = Carbon::today()->subYears($numberOfYears)->startOfDay(); return new static($startDate, $endDate); } public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate) { if ($startDate > $endDate) { throw InvalidPeriod::startDateCannotBeAfterEndDate($startDate, $endDate); } $this->startDate = $startDate; $this->endDate = $endDate; } }