]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/intl/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / DateFormatter / DateFormat / QuarterTransformer.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Intl\DateFormatter\DateFormat;
13
14 /**
15 * Parser and formatter for quarter format
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 */
19 class QuarterTransformer extends Transformer
20 {
21 /**
22 * {@inheritDoc}
23 */
24 public function format(\DateTime $dateTime, $length)
25 {
26 $month = (int) $dateTime->format('n');
27 $quarter = (int) floor(($month - 1) / 3) + 1;
28 switch ($length) {
29 case 1:
30 case 2:
31 return $this->padLeft($quarter, $length);
32 case 3:
33 return 'Q'.$quarter;
34 default:
35 $map = array(1 => '1st quarter', 2 => '2nd quarter', 3 => '3rd quarter', 4 => '4th quarter');
36
37 return $map[$quarter];
38 }
39 }
40
41 /**
42 * {@inheritDoc}
43 */
44 public function getReverseMatchingRegExp($length)
45 {
46 switch ($length) {
47 case 1:
48 case 2:
49 return '\d{'.$length.'}';
50 case 3:
51 return 'Q\d';
52 default:
53 return '(?:1st|2nd|3rd|4th) quarter';
54 }
55 }
56
57 /**
58 * {@inheritDoc}
59 */
60 public function extractDateOptions($matched, $length)
61 {
62 return array();
63 }
64 }