From 8cb8a9ef45192a22eefded7ec84f0e51d6e9b9ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20R=C3=BCtter?= Date: Thu, 25 Jun 2026 21:14:17 +0000 Subject: [PATCH] Fix single-mode date fieldtype crashing when saving with a time The Control Panel submits a single date that includes a time as a ['date' => ..., 'time' => ...] array, but processSingle() passed it straight to Carbon::parse(), which throws a TypeError on arrays. This hit the default date field, whose default save format (Y-m-d H:i) makes formatHasTime() true regardless of time_enabled. Combine the date and time into a single string before parsing, and treat a missing date as an empty value. --- src/Fieldtypes/Date.php | 11 +++++++++++ tests/Fieldtypes/DateTest.php | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Fieldtypes/Date.php b/src/Fieldtypes/Date.php index 3d27b639196..c5c6274db17 100644 --- a/src/Fieldtypes/Date.php +++ b/src/Fieldtypes/Date.php @@ -228,6 +228,17 @@ private function processSingle($data) return null; } + // If the value is an array, the CP has submitted the date and time separately. + // We'll combine them into a single string before parsing, since Carbon can't + // parse an array. A missing date means the field was left empty. + if (is_array($data)) { + if (! ($data['date'] ?? null)) { + return null; + } + + $data = $data['date'].' '.(($data['time'] ?? null) ?: '00:00'); + } + return $this->processDateTime($data); } diff --git a/tests/Fieldtypes/DateTest.php b/tests/Fieldtypes/DateTest.php index b0050887beb..2ac9cd4d7b2 100644 --- a/tests/Fieldtypes/DateTest.php +++ b/tests/Fieldtypes/DateTest.php @@ -244,6 +244,24 @@ public static function processProvider() ['start' => '2012-08-29', 'end' => '2013-09-27'], ['start' => '2012-08-29', 'end' => '2013-09-27'], ], + 'single with date and time array from cp' => [ + 'UTC', + [], + ['date' => '2012-08-29', 'time' => '13:43'], + '2012-08-29 13:43', + ], + 'single with date array and no time' => [ + 'UTC', + [], + ['date' => '2012-08-29', 'time' => null], + '2012-08-29 00:00', + ], + 'single with empty date array' => [ + 'UTC', + [], + ['date' => null, 'time' => null], + null, + ], ]; }