Avoid crash by empty allow_sub_detail or cart.
Use page_datetime to obtain accurate DeliveryWindow.
Convert datetime to timezone aware datetime before calculation.