Conditions | 3 |
Paths | 3 |
Total Lines | 13 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public static function extractDate(string $filepath): DateTimeInterface |
||
29 | { |
||
30 | if (! preg_match(static::DATE_PATTERN, basename($filepath), $matches)) { |
||
31 | throw new InvalidArgumentException('The given filepath does not contain a valid ISO 8601 date prefix.'); |
||
32 | } |
||
33 | |||
34 | $dateString = $matches[1]; |
||
35 | |||
36 | if (isset($matches[2])) { |
||
37 | $dateString .= ' '.str_replace('-', ':', $matches[2]); |
||
38 | } |
||
39 | |||
40 | return new DateTime($dateString); |
||
41 | } |
||
48 |