1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
|
|
|
4 |
|
|
|
5 |
class DateTime extends DateTimeWizard
|
|
|
6 |
{
|
|
|
7 |
/**
|
|
|
8 |
* @var string[]
|
|
|
9 |
*/
|
|
|
10 |
protected array $separators;
|
|
|
11 |
|
|
|
12 |
/**
|
|
|
13 |
* @var array<DateTimeWizard|string>
|
|
|
14 |
*/
|
|
|
15 |
protected array $formatBlocks;
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* @param null|string|string[] $separators
|
|
|
19 |
* If you want to use only a single format block, then pass a null as the separator argument
|
|
|
20 |
* @param DateTimeWizard|string ...$formatBlocks
|
|
|
21 |
*/
|
|
|
22 |
public function __construct($separators, ...$formatBlocks)
|
|
|
23 |
{
|
|
|
24 |
$this->separators = $this->padSeparatorArray(
|
|
|
25 |
is_array($separators) ? $separators : [$separators],
|
|
|
26 |
count($formatBlocks) - 1
|
|
|
27 |
);
|
|
|
28 |
$this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
private function mapFormatBlocks(DateTimeWizard|string $value): string
|
|
|
32 |
{
|
|
|
33 |
// Any date masking codes are returned as lower case values
|
|
|
34 |
if ($value instanceof DateTimeWizard) {
|
|
|
35 |
return $value->__toString();
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
// Wrap any string literals in quotes, so that they're clearly defined as string literals
|
|
|
39 |
return $this->wrapLiteral($value);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public function format(): string
|
|
|
43 |
{
|
|
|
44 |
return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
|
|
|
45 |
}
|
|
|
46 |
}
|