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
12namespace Symfony\Component\Intl\DateFormatter\DateFormat;
13
14/**
15 * Parser and formatter for 24 hour format (0-23).
16 *
17 * @author Igor Wiedler <igor@wiedler.ch>
18 *
19 * @internal
20 */
21class Hour2400Transformer extends HourTransformer
22{
23    /**
24     * {@inheritdoc}
25     */
26    public function format(\DateTime $dateTime, $length)
27    {
28        return $this->padLeft($dateTime->format('G'), $length);
29    }
30
31    /**
32     * {@inheritdoc}
33     */
34    public function normalizeHour($hour, $marker = null)
35    {
36        $marker = (string) $marker;
37
38        if ('AM' === $marker) {
39            $hour = 0;
40        } elseif ('PM' === $marker) {
41            $hour = 12;
42        }
43
44        return $hour;
45    }
46
47    /**
48     * {@inheritdoc}
49     */
50    public function getReverseMatchingRegExp($length)
51    {
52        return '\d{1,2}';
53    }
54
55    /**
56     * {@inheritdoc}
57     */
58    public function extractDateOptions($matched, $length)
59    {
60        return [
61            'hour' => (int) $matched,
62            'hourInstance' => $this,
63        ];
64    }
65}
66