Urgent.News

What's breaking now, across thousands of outlets.

Tech

Bitmask Calendars: How I Built Fast, Timezone-Safe Slot Availability in Flutter

Drivers Lesson lets a student pick a driving instructor, see which time slots are actually free, book one, and pay for it — with 3DS card verification in the loop. The booking screen looks simple: a calendar, a list of times, a confirm button. Almost none of the actual difficulty is in that UI. It's in deciding, correctly and quickly, which slots to show in the first place. Three things made this…

Bitmask calendars provide fast, timezone-safe slot availability in Flutter applications. The author explains how they implemented this feature in their Drivers Lesson app. Instead of using a list of booleans for each 30-minute time slot, they represented a day's availability as a single integer bitmask. Each bit in the bitmask corresponds to a specific time slot, with a set bit indicating that the slot is available.

This approach allows for efficient bitwise arithmetic operations when computing, filtering, and updating availability.

To handle recurring availability for instructors, extra sessions, and existing bookings, the author combines the relevant data sources using bitwise operations. They first merge the availability masks of all sources, then remove any slots that are already booked or blocked by a day off. This process simplifies the logic required to determine if a specific time slot is available for booking.

The author emphasizes the importance of handling timezone differences correctly. Every slot is generated, stored, and compared as UTC internally, while the UI displays the local time only for presentation purposes. This ensures that there are no discrepancies caused by different timezones when checking slot availability or deduplicating overlapping slots.

When a student confirms a slot for booking, the app triggers a Stripe payment with 3D Secure verification. The payment process is treated as a dependency on the availability, ensuring that the payment is only processed if the slot remains available at the time of booking. This sequential dependency prevents stale UI data from causing payment errors.

The author concludes by recommending that teams building similar features should model availability as a small, composable data structure before resorting to per-slot booleans. They also stress the importance of performing all comparisons in UTC and converting to local time only for display purposes. Finally, they suggest checking the slot's bookability right before payment, rather than relying on cached values from when the booking sheet was opened.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Stop Guessing What Your Code Change Will Break

Ever changed one function, thought it was a small edit, then spent the next hour tracing through five other files to figure out what broke? That's the problem I set out to fix.

  • Change Impact Analyzer is a Visual Studio Code extension
  • Parses Python files with tree-sitter and pylsp
  • Recommends fixes and updates affected code automatically

More from Tuesday 1 September →