private function getDeliveryDateByPositions(DeliveryPositionCollection
$positions): DeliveryDate
{ // this function is only called if the provided collection contains a deliverable line item
$max =
$positions->
first()->
getDeliveryDate();
foreach ($positions as $position) { $date =
$position->
getDeliveryDate();
// detect the latest delivery date
$earliest =
$max->
getEarliest() >
$date->
getEarliest() ?
$max->
getEarliest() :
$date->
getEarliest();
$latest =
$max->
getLatest() >
$date->
getLatest() ?
$max->
getLatest() :
$date->
getLatest();
// if earliest and latest is same date, add one day buffer
if ($earliest->
format('Y-m-d'
) ===
$latest->
format('Y-m-d'
)) { $latest =
$latest->
add(new \
DateInterval('P1D'
));
} $max =
new DeliveryDate($earliest,
$latest);
}