Skip to content

Commit

Permalink
Index date intervals that use null as one of the ends. (#110)
Browse files Browse the repository at this point in the history
* Handle date intervals with null signifying open.
  • Loading branch information
rosiel authored Nov 9, 2023
1 parent 1bd54fe commit e799093
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Plugin/search_api/processor/EDTFYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function addFieldValues(ItemInterface $item) {
}, $dates->getDates());
}
else {
// Open start dates.
// Open start dates with `../`.
if (substr($edtf, 0, 3) === '../') {
if ($this->configuration['ignore_open_start']) {
$edtf = substr($edtf, 3);
Expand All @@ -166,17 +166,35 @@ public function addFieldValues(ItemInterface $item) {
$edtf = str_replace('../', $this->configuration['open_start_year'] . '/', $edtf);
}
}
// Open end dates.
// Open start dates with `/`.
if (substr($edtf, 0, 1) === '/') {
if ($this->configuration['ignore_open_start']) {
$edtf = substr($edtf, 1);
}
else {
$edtf = str_replace('/', $this->configuration['open_start_year'] . '/', $edtf);
}
}
// Open end dates with `/..`.
if (substr($edtf, -3) === '/..') {
if ($this->configuration['ignore_open_end']) {
$edtf = substr($edtf, 0, -3);
}
else {
$end_year = (empty($this->configuration['open_end_year'])) ? date('Y') : $this->configuration['open_end_year'];
$edtf = str_replace('/..', '/' . $this->configuration['open_end_year'], $edtf);
$edtf = str_replace('/..', '/' . $end_year, $edtf);
}
}
// Open end dates with `/`.
if (substr($edtf, -1) === '/') {
if ($this->configuration['ignore_open_end']) {
$edtf = substr($edtf, 0, -1);
}
else {
$end_year = (empty($this->configuration['open_end_year'])) ? date('Y') : $this->configuration['open_end_year'];
$edtf = str_replace('/', '/' . $end_year, $edtf);
}
}

$parsed = $parser->parse($edtf)->getEdtfValue();
$years = range(intval(date('Y', $parsed->getMin())), intval(date('Y', $parsed->getMax())));
}
Expand Down

0 comments on commit e799093

Please sign in to comment.