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 * Date formatter.
16 *
17 * <pre>
18 * <?php
19 *
20 * namespace ICanBoogie\CLDR;
21 *
22 * $datetime = '2013-11-05 21:22:23';
23 *
24 * $formatter = new DateFormatter($repository->locales['en']);
25 *
26 * echo $formatter($datetime, 'full'); // Tuesday, November 5, 2013
27 * echo $formatter($datetime, 'long'); // November 5, 2013
28 * echo $formatter($datetime, 'medium'); // Nov 5, 2013
29 * echo $formatter($datetime, 'short'); // 11/5/13
30 *
31 * $formatter = new DateFormatter($repository->locales['fr']);
32 *
33 * echo $formatter($datetime, 'full'); // mardi 5 novembre 2013
34 * echo $formatter($datetime, 'long'); // 5 novembre 2013
35 * echo $formatter($datetime, 'medium'); // 5 nov. 2013
36 * echo $formatter($datetime, 'short'); // 05/11/2013
37 * </pre>
38 */
39 class DateFormatter extends DateTimeFormatter
40 {
41 /**
42 * Resolves widths defined in `dateFormats` (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['dateFormats'][$pattern_or_width_or_skeleton];
51 }
52
53 return parent::resolve_pattern($pattern_or_width_or_skeleton);
54 }
55 }