Problem/Motivation

When the month facet parses a YYYY-MM value without a day, PHP fills in the current day of the month. If that day does not exist in the parsed month, parsing fails. For example, on the 31st, parsing 2026-02 with the Y-m format can produce an invalid date because February has no 31st. (I can reproduce this today on Sept 29th and Sept 30th.

Running Drupal 10.6.17
PHP 8.4.26
Facets 3.0.7

On Sept 29th, 30th load the page with the month-based facet parses month value such as 2026-02.

Logs the error:
UnexpectedValueException: The created date does not match the input value. in Drupal\Component\Datetime\DateTimePlus::createFromFormat() (line 269 of /code/web/core/lib/Drupal/Component/Datetime/DateTimePlus.php).

I used AI to troubleshoot and found that patching with a one liner adding a day (1) seems to suppress the error:

diff --git a/src/Plugin/facets/query_type/SearchApiDate.php b/src/Plugin/facets/query_type/SearchApiDate.php
--- a/src/Plugin/facets/query_type/SearchApiDate.php
+++ b/src/Plugin/facets/query_type/SearchApiDate.php
@@ -282,7 +282,7 @@ class SearchApiDate extends QueryTypeRangeBase {

case static::FACETAPI_DATE_MONTH:
$format = 'F Y';
- $dateTime = $dateTime::createFromFormat('Y-m', $raw_value);
+ $dateTime = $dateTime::createFromFormat('Y-m-d', $raw_value . '-01');
break;

case static::FACETAPI_DATE_DAY:

Posting for feedback in case I'm missing something. Has anyone seen this before?

Comments

dinonet created an issue. See original summary.

dinonet’s picture

Issue summary: View changes
dinonet’s picture

Issue summary: View changes