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\Pair; |
15
|
|
|
use function Seboettg\Collection\Map\emptyMap; |
16
|
|
|
use function Seboettg\Collection\Map\mapOf; |
17
|
|
|
use function Seboettg\Collection\Map\pair; |
18
|
|
|
|
19
|
|
|
class YearMonthRenderer extends DateRangeRenderer |
20
|
|
|
{ |
21
|
|
|
public function parseDateRange( |
22
|
|
|
ListInterface $datePartsList, |
23
|
|
|
DateTime $from, |
24
|
|
|
DateTime $to, |
25
|
|
|
string $delimiter |
26
|
|
|
): string { |
27
|
|
|
$dp = $datePartsList->toArray(); |
28
|
|
|
$dateParts = []; |
29
|
|
|
array_walk($dp, function (Pair $datePartPair) use (&$dateParts) { |
30
|
|
|
$datePart = $datePartPair->getValue(); |
31
|
|
|
$key = $datePartPair->getKey(); |
32
|
|
|
if (strpos($key, "year") !== false || strpos($key, "month") !== false) { |
|
|
|
|
33
|
|
|
$dateParts["yearmonth"][] = $datePart; |
34
|
|
|
} |
35
|
|
|
if (strpos($key, "day") !== false) { |
36
|
|
|
$dateParts["day"] = $datePart; |
37
|
|
|
} |
38
|
|
|
}); |
39
|
|
|
$map = emptyMap(); |
40
|
|
|
$map->setArray($dateParts); |
41
|
|
|
return $this->renderDateParts($map->toList(), $from, $to, $delimiter); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|