chengkun
2025-09-09 774d962b76d63366ed26c395e0a33cdbec309242
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
 
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
 
class Date extends DateTimeWizard
{
    /**
     * Year (4 digits), e.g. 2023.
     */
    public const YEAR_FULL = 'yyyy';
 
    /**
     * Year (last 2 digits), e.g. 23.
     */
    public const YEAR_SHORT = 'yy';
 
    public const MONTH_FIRST_LETTER = 'mmmmm';
    /**
     * Month name, long form, e.g. January.
     */
    public const MONTH_NAME_FULL = 'mmmm';
    /**
     * Month name, short form, e.g. Jan.
     */
    public const MONTH_NAME_SHORT = 'mmm';
    /**
     * Month number with a leading zero if required, e.g. 01.
     */
    public const MONTH_NUMBER_LONG = 'mm';
 
    /**
     * Month number without a leading zero, e.g. 1.
     */
    public const MONTH_NUMBER_SHORT = 'm';
 
    /**
     * Day of the week, full form, e.g. Tuesday.
     */
    public const WEEKDAY_NAME_LONG = 'dddd';
 
    /**
     * Day of the week, short form, e.g. Tue.
     */
    public const WEEKDAY_NAME_SHORT = 'ddd';
 
    /**
     * Day number with a leading zero, e.g. 03.
     */
    public const DAY_NUMBER_LONG = 'dd';
 
    /**
     * Day number without a leading zero, e.g. 3.
     */
    public const DAY_NUMBER_SHORT = 'd';
 
    protected const DATE_BLOCKS = [
        self::YEAR_FULL,
        self::YEAR_SHORT,
        self::MONTH_FIRST_LETTER,
        self::MONTH_NAME_FULL,
        self::MONTH_NAME_SHORT,
        self::MONTH_NUMBER_LONG,
        self::MONTH_NUMBER_SHORT,
        self::WEEKDAY_NAME_LONG,
        self::WEEKDAY_NAME_SHORT,
        self::DAY_NUMBER_LONG,
        self::DAY_NUMBER_SHORT,
    ];
 
    public const SEPARATOR_DASH = '-';
    public const SEPARATOR_DOT = '.';
    public const SEPARATOR_SLASH = '/';
    public const SEPARATOR_SPACE_NONBREAKING = "\u{a0}";
    public const SEPARATOR_SPACE = ' ';
 
    protected const DATE_DEFAULT = [
        self::YEAR_FULL,
        self::MONTH_NUMBER_LONG,
        self::DAY_NUMBER_LONG,
    ];
 
    /**
     * @var string[]
     */
    protected array $separators;
 
    /**
     * @var string[]
     */
    protected array $formatBlocks;
 
    /**
     * @param null|string|string[] $separators
     *        If you want to use the same separator for all format blocks, then it can be passed as a string literal;
     *           if you wish to use different separators, then they should be passed as an array.
     *        If you want to use only a single format block, then pass a null as the separator argument
     */
    public function __construct($separators = self::SEPARATOR_DASH, string ...$formatBlocks)
    {
        $separators ??= self::SEPARATOR_DASH;
        $formatBlocks = (count($formatBlocks) === 0) ? self::DATE_DEFAULT : $formatBlocks;
 
        $this->separators = $this->padSeparatorArray(
            is_array($separators) ? $separators : [$separators],
            count($formatBlocks) - 1
        );
        $this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
    }
 
    private function mapFormatBlocks(string $value): string
    {
        // Any date masking codes are returned as lower case values
        if (in_array(mb_strtolower($value), self::DATE_BLOCKS, true)) {
            return mb_strtolower($value);
        }
 
        // Wrap any string literals in quotes, so that they're clearly defined as string literals
        return $this->wrapLiteral($value);
    }
 
    public function format(): string
    {
        return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
    }
}