1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/* |
4
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
5
|
|
|
* @copyright Copyright (c) 2019 Sebastian Böttger. |
6
|
|
|
* @license https://opensource.org/licenses/MIT |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Seboettg\CiteProc\Rendering\Date\DateRange; |
10
|
|
|
|
11
|
|
|
use Seboettg\CiteProc\Rendering\Date\DatePart; |
12
|
|
|
use Seboettg\CiteProc\Rendering\Date\DateTime; |
13
|
|
|
use Seboettg\Collection\Lists\ListInterface; |
14
|
|
|
use Seboettg\Collection\Map\MapInterface; |
15
|
|
|
use Seboettg\Collection\Map\Pair; |
16
|
|
|
use function Seboettg\Collection\Lists\emptyList; |
17
|
|
|
use function Seboettg\Collection\Lists\listOf; |
18
|
|
|
use function Seboettg\Collection\Map\emptyMap; |
19
|
|
|
use function Seboettg\Collection\Map\mapOf; |
20
|
|
|
use function Seboettg\Collection\Map\pair; |
21
|
|
|
|
22
|
|
|
class MonthDayRenderer extends DateRangeRenderer |
23
|
|
|
{ |
24
|
|
|
public function parseDateRange(ListInterface $datePartsList, DateTime $from, DateTime $to, string $delimiter): string |
25
|
|
|
{ |
26
|
|
|
$dp = $datePartsList->toArray(); |
27
|
|
|
$dateParts_ = []; |
28
|
|
|
array_walk($dp, function (Pair $datePartPair) use (&$dateParts_) { |
29
|
|
|
$datePart = $datePartPair->getValue(); |
30
|
|
|
$key = $datePartPair->getKey(); |
31
|
|
|
if (strpos($key, "month") !== false || strpos($key, "day") !== false) { |
|
|
|
|
32
|
|
|
$dateParts_["monthday"][] = $datePart; |
33
|
|
|
} |
34
|
|
|
if (strpos($key, "year") !== false) { |
35
|
|
|
$dateParts_["year"] = $datePart; |
36
|
|
|
} |
37
|
|
|
}); |
38
|
|
|
$datePartsMap = emptyMap(); |
39
|
|
|
$datePartsMap->setArray($dateParts_); |
40
|
|
|
return $this->renderDateParts($datePartsMap->toList(), $from, $to, $delimiter); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|