Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Fieldtypes/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Fieldtypes/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];
}

Expand Down
Loading