for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\Analytics;
use DateTime;
use Carbon\Carbon;
use Spatie\Analytics\Exceptions\InvalidPeriod;
class Period
{
/** @var \DateTime */
public $startDate;
public $endDate;
public static function create(DateTime $startDate, $endDate): Period
return new static($startDate, $endDate);
}
public static function days(int $numberOfDays): Period
$endDate = Carbon::today();
$startDate = Carbon::today()->subDays($numberOfDays)->startOfDay();
public static function months(int $numberOfMonths): Period
$startDate = Carbon::today()->subMonths($numberOfMonths)->startOfMonth();
public static function years(int $numberOfYears): Period
$startDate = Carbon::today()->subYears($numberOfYears)->startOfYear();
public function __construct(DateTime $startDate, DateTime $endDate)
if ($startDate > $endDate) {
throw InvalidPeriod::startDateCannotBeAfterEndDate($startDate, $endDate);
$this->startDate = $startDate;
$this->endDate = $endDate;