| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Core\Date; |
| 4: | |
| 5: | use Salient\Contract\Core\DateParserInterface; |
| 6: | use Salient\Utility\Date; |
| 7: | use Salient\Utility\Test; |
| 8: | use DateTimeImmutable; |
| 9: | use DateTimeZone; |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | final class DateParser implements DateParserInterface |
| 17: | { |
| 18: | |
| 19: | |
| 20: | |
| 21: | public function parse(string $value, ?DateTimeZone $timezone = null): ?DateTimeImmutable |
| 22: | { |
| 23: | return Test::isDateString($value) |
| 24: | ? Date::maybeSetTimezone( |
| 25: | new DateTimeImmutable($value, $timezone), |
| 26: | $timezone, |
| 27: | ) |
| 28: | : null; |
| 29: | } |
| 30: | } |
| 31: | |