25 lines
607 B
PHP
25 lines
607 B
PHP
<?php
|
|
|
|
namespace App\Domain\Model\Value;
|
|
|
|
final readonly class Date
|
|
{
|
|
public function __construct(
|
|
public ?int $month,
|
|
public ?int $day,
|
|
public int $year,
|
|
) {
|
|
if ($this->month < 1 || $this->month > 12) {
|
|
throw new \InvalidArgumentException('Month must be between 1 and 12');
|
|
}
|
|
|
|
if ($this->day < 1 || $this->day > 31) {
|
|
throw new \InvalidArgumentException('Day must be between 1 and 31');
|
|
}
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->year . '-' . $this->month . '-' . $this->day;
|
|
}
|
|
} |