Skip to content
Merged
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
24 changes: 14 additions & 10 deletions src/resources/views/fields/date_range.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
<?php
// if the column has been cast to Carbon or Date (using attribute casting)
// get the value as a date string
if ( isset($entry) && ($entry->{$field['start_name']} instanceof \Carbon\Carbon || $entry->{$field['start_name']} instanceof \Jenssegers\Date\Date) ) {
$start_name = $entry->{$field['start_name']}->format( 'Y-m-d H:i:s' );
} else {
$start_name = null;
function formatDate($entry, $dateFieldName)
{
$formattedDate = null;
if (isset($entry) && !empty($entry->{$dateFieldName})) {
$dateField = $entry->{$dateFieldName};
if ($dateField instanceof \Carbon\Carbon || $dateField instanceof \Jenssegers\Date\Date) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should attempt to just "duck type" this (i.e. if it's an object that has the format method then call the format method).

$formattedDate = $dateField->format('Y-m-d H:i:s');
} else {
$formattedDate = date('Y-m-d H:i:s', strtotime($entry->{$dateFieldName}));
}
}
return $formattedDate;
}
//Do the same as the above but for the range end field
if ( isset($entry) && ($entry->{$field['end_name']} instanceof \Carbon\Carbon || $entry->{$field['end_name']} instanceof \Jenssegers\Date\Date) ) {
$end_name = $entry->{$field['end_name']}->format( 'Y-m-d H:i:s' );
} else {
$end_name = null;
}
$start_name = formatDate($entry, $field['start_name']);
$end_name = formatDate($entry, $field['end_name']);
?>

<div @include('crud::inc.field_wrapper_attributes') >
Expand Down