dionsnoeijen /
sexy-field
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the SexyField package. |
||
| 5 | * |
||
| 6 | * (c) Dion Snoeijen <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | declare (strict_types = 1); |
||
| 13 | |||
| 14 | namespace Tardigrades\SectionField\ValueObject; |
||
| 15 | |||
| 16 | use Assert\Assertion; |
||
| 17 | |||
| 18 | final class After |
||
| 19 | { |
||
| 20 | /** @var \DateTimeInterface */ |
||
| 21 | private $dateTime; |
||
| 22 | |||
| 23 | private function __construct(\DateTimeInterface $dateTime) |
||
| 24 | { |
||
| 25 | $this->dateTime = $dateTime; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function __toString() |
||
| 29 | { |
||
| 30 | return $this->dateTime->format('Y-m-d\TH:i'); |
||
| 31 | } |
||
| 32 | |||
| 33 | public static function fromString(string $dateTime): self |
||
| 34 | { |
||
| 35 | $format = 'Y-m-d\TH:i'; |
||
| 36 | Assertion::date($dateTime, $format); |
||
| 37 | $dateTime = \DateTimeImmutable::createFromFormat($format, $dateTime); |
||
| 38 | |||
| 39 | return new self($dateTime); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 40 | } |
||
| 41 | |||
| 42 | public static function fromDateTime(\DateTime $dateTime): self |
||
| 43 | { |
||
| 44 | return new self(\DateTimeImmutable::createFromMutable($dateTime)); |
||
| 45 | } |
||
| 46 | } |
||
| 47 |