From e7990931277f447de752413158d8692ea7f5b17b Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Wed, 8 Nov 2023 20:07:31 -0400 Subject: [PATCH] Index date intervals that use null as one of the ends. (#110) * Handle date intervals with null signifying open. --- src/Plugin/search_api/processor/EDTFYear.php | 26 +++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Plugin/search_api/processor/EDTFYear.php b/src/Plugin/search_api/processor/EDTFYear.php index d65c37b..438be8d 100644 --- a/src/Plugin/search_api/processor/EDTFYear.php +++ b/src/Plugin/search_api/processor/EDTFYear.php @@ -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); @@ -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()))); }