In this episode, we tackle a common usability issue with our scheduling app: showing time slots that have already gone by doesn't make sense! For example, if it's currently 12:40pm, there’s no point in allowing users to book a 9am slot on the same day.
We walk through how to programmatically exclude all the times earlier than the current time for today's date. You’ll see how we add a method called excludeTimePastToday
, and make some tweaks so that the earliest available slot is always in the future. For a bit of extra safety, we pad by rounding to the end of the current hour—so if it’s 12:40pm, we won’t let anyone book an appointment starting at 1pm or later, giving us a small buffer between the current time and the next available slot.
The steps are pretty straightforward: we update our periods, adjust the start times accordingly, and set the precision on our times to match the rest of our setup. You'll also see how to set a test time, so we can reliably check that bookings only start from the correct cutoff.
By the end, our availability only shows future slots for today, and we finish up by prepping for the next episode, where we'll write some tests to verify all this logic works as intended.