I have this block of code that was written by someone years ago :-
<?php
class BoDelivery {
public function EstimatedDays($off, $standard_days, $saturday, $delay) {
$today = date("N"); // Weekday - number 1-7
$now = strtotime("now"); // Unix
$off_array = explode(":", str_replace(".", ":", $off));
$off_unix = mktime($off_array[0], $off_array[1], "00", date("n"), date("j"), date("Y"));
$sending_days_from_now = 0;
if ($now > $off_unix) {
$sending_days_from_now++;
}
$sending_day = $today + $sending_days_from_now;
switch ($sending_day) {
case 6:
$sending_days_from_now++;
$sending_days_from_now++;
break;
case 7:
$sending_days_from_now++;
break;
}
$sending_day = $today + $sending_days_from_now;
// Estimated delivery time
$delivery_days = $standard_days;
$over_weekends = 0;
// Add Delay
if ($delay) {
$delivery_days = $delivery_days + $delay;
}
if ($sending_day == 5 && !$saturday) {
$delivery_days++;
$delivery_days++;
$over_weekends++;
}
$delivery_day = $sending_day + $delivery_days;
switch ($delivery_day) {
case 6:
if (!$saturday) {
$delivery_days++;
$delivery_days++;
$over_weekends++;
}
break;
case 7:
$delivery_days++;
$over_weekends++;
break;
}
if ($over_weekends == 0 && $delivery_days > 5) {
$delivery_days++;
$delivery_days++;
}
$delivery_day = $sending_day + $delivery_days;
switch ($delivery_day) {
case 13:
$delivery_days++;
$delivery_days++;
$over_weekends++;
break;
case 14:
$delivery_days++;
$over_weekends++;
break;
}
$delivery_day = $sending_day + $delivery_days;
$delivery_days = $delivery_day - $today;
return $delivery_days;
}
}
?>
Which is supposed to calculate the number of days for delivery, taking into account weekends & with a delay variable that we can set.
It isn’t working as expected, may never have worked(??) or maybe down to PHP upgrades.
For example, if today (18th)I set the delay to 2 days the delivery estimate is the 21st (which is correct), if I change the delay to 3 OR 4 it becomes the 24th, 5 then becomes the 26th!
I can’t get my head around the code at all, I wonder if someone could assist in what may be going on or add comments to the code snippets so I can maybe work it out?
Thanks for any help.