A while back I needed to know how many working days I had left before a deadline. My first instinct was: total days divided by 7, times 5, done. That works fine as long as your date range happens to be a whole number of weeks. The moment you have leftover days at either end — which is basically always — that formula falls apart, because whether a leftover day "counts" depends entirely on which day of the week it lands on. I ended up building a small workday calculator just to get this right, and the actual logic turned out to be less "math" and more "walk the calendar and check."

Full weeks are cheap, partial weeks aren't

The calculator lets you define your own work week (a set of weekday numbers, 0=Sunday through 6=Saturday, defaulting to Mon–Fri) instead of assuming a fixed 5-day week. That's the part that breaks the naive division trick — you can't just multiply by 5 if the user's work week has 4 days or includes Saturday.

Here's the "count workdays between two dates" function, close to what's actually running:

let start = DateTime.fromISO(twoDate.date1);