I was debugging this legacy code and would like to test it.
The goal is to allow someone to choose a delivery frequency for product delivery. If someone wants their product Every Other Week, the system must determine if they should receive the order next week or two weeks later. We call this week or week B.
Keep in mind that I did not write this, I am just trying to figure it out and would like to help evaluate its accuracy:
if (date("l") == "Monday" ) {
$start = 0;
} else if (date("l") == "Tuesday" || date("l") == "Wednesday" || date("l") == "Thursday" || date("l") == "Friday" || date("l") == "Saturday"|| date("l") == "Sunday") {
$start = -1;
}
// if changing to every other week set to next week a/b-ness
$a_week_tid = 34;
$b_week_tid = 35;
$every_other_week_frequency_id = 32;
if ($delivery_frequency == $every_other_week_frequency_id) {
$julian = (int) (strtotime('Monday +' . $start . ' week') / 86400);
$julian_week = ($julian-4) / 7;
if ($julian_week % 2) {
$today_a_or_b = $b_week_tid;
$next_week_a_or_b = $a_week_tid;
$a_or_b_week_string = '(A Week)';
} else {
$today_a_or_b = $a_week_tid;
$next_week_a_or_b = $b_week_tid;
$a_or_b_week_string = '(B Week)';
}
} else {
$next_week_a_or_b = NULL;
$a_or_b_week_string = NULL;
}
This code is not commented on or documented. Part of me is embarrassed:
- Why is 4 subtracted from Julian, then divisible by 7?
- If today is Monday, $ julian_week is 2129, and 2129% 2 evaluates to TRUE. It is right?
- , ? ('w') ?