In this episode, we're tackling how to handle schedule exclusions like holidays, lunch breaks, or any time an employee shouldn't be available. We dive into the code where we build out employee availability, and we extend it so that after adding up available time, we also loop through all the schedule exclusions for each employee.
We'll walk through subtracting these exclusions from their schedules—so if someone has a lunch break or a day off, they won't be shown as available. There's some discussion about improving performance by scoping exclusions more narrowly (something we might come back to), but for now, we safely avoid any nasty database performance issues.
After tweaking the logic, we also remember to update our database structure, making sure the schedule exclusion fields are set to handle date and time properly—not just dates! Once that's set, we add a sample lunch break directly in the database and refresh the browser to see the effect.
You'll see that the available period is now automatically split around that lunch break, showing two blocks of time: before and after the break. Everything works as expected: first, you see availability from the start of the shift until lunch, then from after lunch until the end. Nice and clean!