In this episode, we dive into setting up employee schedules and handling schedule exclusions for things like holidays. First, we start by designing our schedule
model (or schema), which covers when an employee is generally available to work. We talk through creating the migration and model, making sure each day of the week has its own start and end time columns. That way, you have the flexibility to set up detailed weekly schedules for each employee, including the option to have schedules that only run for specific periods (like a year, or just six months).
We then hook up the necessary relationships in our models so each employee can have multiple schedules, and vice versa, making the data structure nice and flexible. We also set up casting for the date fields, which will help later when we're working with date and time values in code.
Next, we look at the factory setup so when we run our tests, we don't have to keep repeating the whole weekly schedule for each test -- it's all set up to default to 9-to-5 working hours, making life easier.
After covering basic schedule setup, we switch over to handling schedule exclusions (like staff holidays or one-off days off). This part is much simpler: we create a separate schedule_exclusion
model, allowing you to block out periods of time (with flexible start and end datetimes) where an employee is NOT available. We wire this up with relationships, and cast the fields for easy use with date packages.
By the end, you'll have a robust framework for storing both comprehensive employee working hours and any temporary exclusions to their schedules—ready for more advanced logic in the upcoming episodes!