Total Complexity | 6 |
Total Lines | 22 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | abstract class DateUtil |
||
10 | { |
||
11 | public const ISO_DATE_FORMAT = 'Y-m-d'; |
||
12 | |||
13 | public static function parseDate($date, string $format = self::ISO_DATE_FORMAT): DateTimeInterface |
||
14 | { |
||
15 | $date = self::tryParseDate($date, $format); |
||
16 | |||
17 | if (!$date) { |
||
|
|||
18 | throw new InvalidArgumentException("Invalid date format ($date does not conform to $format)"); |
||
19 | } |
||
20 | |||
21 | return $date; |
||
22 | } |
||
23 | |||
24 | public static function tryParseDate($date, string $format = self::ISO_DATE_FORMAT): ?DateTimeInterface |
||
31 | } |
||
32 | } |
||
33 |