<?php

function smarty_function_get_incremented_delivery_date($params, &$smarty)
{
    if (empty($params['date'])) {
        throw new InvalidArgumentException('Missing \'date\' parameter');
    }

    if (empty($params['id_product']) && empty($params['cart'])) {
        throw new InvalidArgumentException('Invalid use of \'get_incremented_delivery_date\' - parameter \'id_product\' or \'cart\' is missing');
    }

    $date = $params['date'];
    if (!($date instanceof DateTime)) {
        $date = new DateTime($date);
    }

    $result = $date;

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
