Calculating if vehicle's mileage is in service window I'm trying to calculate whether a given vehicle's mileage is within the recommended service windows.

For example, if a fuel filter replacement is every 15,000 miles and the service window is 5,000 miles, then a vehicle is within the service window from 12,500-17,500 miles, 27,500-32,500 miles, etc.

My current logic works (I think), but I'm not sure if it's too convoluted or if there are better ways of figuring this out:

$mileage = 27500;
$service = 15000;
$window = 2500;
$is_due = $mileage &lt; $service
    ? $service - $mileage &lt;= $window
    : $mileage % service &lt;= $window
        || abs($mileage % $service - $service) &lt;= $window;
This seems overly complex or not complex enough.  If the fuel filter is replaced at 12,500, then the next service window should be from 25,000 to 30,000, not 27,500 to 32,500.  

If the fuel filter is not replaced by 17,500, it doesn't go back into service either.  It still needs replaced at 18,000, etc.  

$current_mileage = 27500;
$last_service = 12500;
$service_interval = 15000;
$half_window = 2500;

$is_due = $current_mileage + $half_window &lt;= $last_service + $service_interval;

$is_overdue = $current_mileage &gt; $last_service + $service_interval + $half_window;


This seems to better reflect how service windows work in practice.