1 <?php
2
3 /*
4 * This file is part of the ICanBoogie package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace ICanBoogie\CLDR;
13
14 /**
15 * Time formatter.
16 *
17 * <pre>
18 * <?php
19 *
20 * namespace ICanBoogie\CLDR;
21 *
22 * $datetime = '2013-11-05 21:22:23';
23 *
24 * $formatter = new TimeFormatter($repository->locales['en']);
25 *
26 * echo $formatter($datetime, 'full'); // 9:22:23 PM CET
27 * echo $formatter($datetime, 'long'); // 9:22:23 PM CET
28 * echo $formatter($datetime, 'medium'); // 9:22:23 PM
29 * echo $formatter($datetime, 'short'); // 9:22 PM
30 *
31 * $formatter = new TimeFormatter($repository->locales['fr']);
32 *
33 * echo $formatter($datetime, 'full'); // 21:22:23 CET
34 * echo $formatter($datetime, 'long'); // 21:22:23 CET
35 * echo $formatter($datetime, 'medium'); // 21:22:23
36 * echo $formatter($datetime, 'short'); // 21:22
37 * </pre>
38 */
39 class TimeFormatter extends DateTimeFormatter
40 {
41 /**
42 * Resolves widths defined in `timeFormats` (full, long, medium, short) into a pattern.
43 */
44 protected function resolve_pattern($pattern_or_width_or_skeleton)
45 {
46 static $widths = array('full', 'long', 'medium', 'short');
47
48 if (in_array($pattern_or_width_or_skeleton, $widths))
49 {
50 return $this->calendar['timeFormats'][$pattern_or_width_or_skeleton];
51 }
52
53 return parent::resolve_pattern($pattern_or_width_or_skeleton);
54 }
55 }