In this episode, we dive into handling date periods to build up employee availability for appointments and bookings. We introduce the period
package from Sparsely, which makes it simple to manage complex periods of time—imagine easily defining an employee's work schedule, then subtracting their time off and existing bookings to show only what's actually available.
First, we install the package and set up a new ScheduleAvailability
class, which will hold all of our logic. We walk through how period collections work: you can add a period (like an entire workday) and then subtract periods (such as lunch breaks or appointments), and the collection automatically splits your available times accordingly.
With some quick examples, you'll see how removing a booked slot from a full day period leaves you with the real free time. We also talk about how to handle boundaries (like whether periods include or exclude start and end times), because that's crucial to avoid weird overlapping slots.
By the end of the video, you'll have a clear understanding of using this package to dynamically manage availability. We're just getting the basics in place here, but you'll see how subtracting out unavailability or appointments cleanly leaves only accurate open slots for future steps in our booking workflow.