-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTimeFormatter.php
44 lines (41 loc) · 1.38 KB
/
TimeFormatter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace ICanBoogie\CLDR\Dates;
/**
* Time formatter.
*
* ```php
* <?php
*
* namespace ICanBoogie\CLDR;
*
* $datetime = '2013-11-05 21:22:23';
*
* $format = new TimeFormatter($repository->locales['en'])->format(...);
*
* echo $format($datetime, DateTimeFormatLength::FULL); // 9:22:23 PM CET
* echo $format($datetime, DateTimeFormatLength::LONG); // 9:22:23 PM CET
* echo $format($datetime, DateTimeFormatLength::MEDIUM); // 9:22:23 PM
* echo $format($datetime, DateTimeFormatLength::SHORT); // 9:22 PM
*
* $format = new TimeFormatter($repository->locales['fr'])->format(...);
*
* echo $format($datetime, DateTimeFormatLength::FULL); // 21:22:23 CET
* echo $format($datetime, DateTimeFormatLength::LONG); // 21:22:23 CET
* echo $format($datetime, DateTimeFormatLength::MEDIUM); // 21:22:23
* echo $format($datetime, DateTimeFormatLength::SHORT); // 21:22
* ```
*/
final class TimeFormatter extends DateTimeFormatter
{
/**
* Resolves length defined in `timeFormats` into a pattern.
*/
protected function resolve_pattern(
string|DateTimeFormatLength|DateTimeFormatId $pattern_or_length_or_id
): string {
if ($pattern_or_length_or_id instanceof DateTimeFormatLength) {
return $this->calendar['timeFormats'][$pattern_or_length_or_id->value];
}
return parent::resolve_pattern($pattern_or_length_or_id);
}
}