1 | <?php declare(strict_types = 1); |
||
13 | class Normalizer |
||
14 | { |
||
15 | /** |
||
16 | * Used to turn a given non-strtotime-compatible time string into a compatible one |
||
17 | * Only modifies the non-strtotime-compatible time strings provided leaving the rest intact |
||
18 | * |
||
19 | * @var string $pattern |
||
20 | */ |
||
21 | public static $pattern = <<<'REGEX' |
||
22 | ~ |
||
23 | # grab the integer part of time string |
||
24 | \s? (?<int> \d{1,5}) \s? |
||
25 | # match only the shortest abbreviations that aren't supported by strtotime |
||
26 | (?<time> |
||
27 | (?: s (?=(?:ec(?:ond)?s?)?(?:\b|\d)) |
||
28 | | m (?=(?:in(?:ute)?s?)?(?:\b|\d)) |
||
29 | | h (?=(?:(?:ou)?rs?)?(?:\b|\d)) |
||
30 | | d (?=(?:ays?)?(?:\b|\d)) |
||
31 | | w (?=(?:eeks?)?(?:\b|\d)) |
||
32 | | mon (?=(?:(?:th)?s?)?(?:\b|\d)) |
||
33 | ) |
||
34 | ) |
||
35 | [^\d]*?(?=\b|\d) |
||
36 | # do only extract start of string |
||
37 | | (?<text> .+) |
||
38 | ~uix |
||
39 | REGEX; |
||
40 | |||
41 | /** |
||
42 | * Turns any non-strtotime-compatible time string into a compatible one. |
||
43 | * If the passed input has trailing data, it won't be lost since within the callback the input is reassembled. |
||
44 | * However no leading data is accepted. |
||
45 | * |
||
46 | * @param string $input |
||
47 | * @return string |
||
48 | */ |
||
49 | 4 | public function normalize(string $input): string |
|
92 | } |
||
93 |