1<?php
2/**
3 * This file is part of the FreeDSx ASN1 package.
4 *
5 * (c) Chad Sikorra <Chad.Sikorra@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11namespace FreeDSx\Asn1\Type;
12
13/**
14 * Represents a UTC Time type.
15 *
16 * @author Chad Sikorra <Chad.Sikorra@gmail.com>
17 */
18class UtcTimeType extends AbstractTimeType
19{
20    /**
21     * Only a 2 day year (was Y2K not a thing back then?), seconds are optional, Z or time differential.
22     */
23    public const TIME_REGEX = '~^
24        (\d\d)                # 1 - Year
25        (\d\d)                # 2 - Month
26        (\d\d)                # 3 - Day
27        (\d\d)                # 4 - Hour
28        (\d\d)                # 5 - Minutes
29        (\d\d)?               # 6 - Seconds, which are optional
30        (Z|[\+\-]\d\d\d\d)    # 7 - Timezone modifier (not optional). It can either be a Z (UTC) or a time differential.
31    $~x';
32
33    public const REGEX_MAP = [
34        'hours' => 4,
35        'minutes' => 5,
36        'seconds' => 6,
37        'timezone' => 7,
38    ];
39
40    protected $tagNumber = self::TAG_TYPE_UTC_TIME;
41
42    /**
43     * Valid datetime formats.
44     */
45    protected $validDateFormats = [
46        self::FORMAT_SECONDS,
47        self::FORMAT_MINUTES,
48    ];
49
50    /**
51     * Valid timezone formats
52     */
53    protected $validTzFormats = [
54        self::TZ_UTC,
55        self::TZ_DIFF,
56    ];
57
58    /**
59     * {@inheritdoc}
60     */
61    public function __construct(?\DateTime $dateTime = null, string $dateFormat = self::FORMAT_SECONDS, string $tzFormat = self::TZ_UTC)
62    {
63        parent::__construct($dateTime, $dateFormat, $tzFormat);
64    }
65}
66