A staff shift scheduling tool, and the rules it has to encode
Saudi labour law says a worker may not stay at the workplace more than twelve hours in a single day, and may not work more than five consecutive hours without a break. The EU working time directive sets eleven consecutive hours of daily rest. Those are not preferences a manager balances. They are the validation rules, and a rota tool that cannot express them is a prettier spreadsheet.
Nearly every shift rota we are asked to replace is a spreadsheet, and nearly every one of them works. People are not stupid. A manager who has run the same twenty staff for three years holds the constraints in their head and produces a rota in an hour.
What breaks is not the rota. It is the change. Someone calls in sick on a Thursday, the manager swaps two names, and the swap quietly creates a shift pattern that was not legal. Nobody notices, because nothing in a spreadsheet notices. That is the actual problem a scheduling tool solves, and it is a validation problem rather than a calendar problem.
The constraints are published, and they are not yours to choose
Before any screen gets designed, the rules have to be written down, because they are the schema. Saudi Arabia's labour law is specific and the Ministry of Human Resources and Social Development publishes it in English. Read it as a list of validations rather than as employment policy (Work conditions and circumstances, MHRSD).
| Rule | What the text says | What it is in the tool |
|---|---|---|
| Daily and weekly hours | Not more than eight actual working hours per day, or forty-eight hours per week | A hard cap, checked per day and per week |
| Ramadan | Reduced for Muslim workers so as not to exceed six hours per day or thirty-six hours per week | A date-dependent cap, and a per-person attribute |
| Consecutive hours | Must not work more than five consecutive hours without a break for rest, prayer and meals | A break must be inserted inside any shift over five hours |
| Break length | Not less than half an hour at a time | Minimum duration on each inserted break |
| Time on site | May not stay at the workplace for more than twelve hours in a single day | A ceiling on span, not on worked hours |
| Weekly rest | Friday, paid, not less than twenty-four consecutive hours, and not replaceable with a cash payment | A protected block per person per week |
| Shift work | With Ministry approval, limits may be exceeded if the average over a period of three weeks or less stays within them | An averaging window, if the approval exists |
Three of those rows catch teams out. The twelve hour span limit is about presence, not work, so a split shift with a long unpaid gap can breach it while the worked hours look fine. The weekly rest cannot be bought out, so a tool that offers "pay instead of day off" as an option is offering something the law does not. And the break is not counted as working time, with the law adding that the employer may not require the worker to remain at the workplace during it, which is a different thing from scheduling a break and leaving them on the floor.
The European set, which is stricter in a different place
If any part of the operation sits in or sells into the EU, a second set applies, and it constrains the gaps rather than the hours. Directive 2003/88/EC gives every worker "a minimum daily rest period of 11 consecutive hours per 24-hour period" in Article 3, and in Article 5 "a minimum uninterrupted rest period of 24 hours plus the 11 hours' daily rest" each week (Directive 2003/88/EC, EUR-Lex).
The eleven hour rule is the one that quietly invalidates rotas, because it is a constraint between two shifts rather than inside one. A late finish followed by an early start is the classic breach, and it is exactly the shape a well meaning manual swap produces.
- Weekly hours are averaged. Article 6 limits "the average working time for each seven-day period, including overtime" to 48 hours, and Article 16(b) permits a reference period "not exceeding four months." So the check is a rolling average, not a per-week ceiling.
- Night work has its own cap. Article 8 requires that "normal hours of work for night workers do not exceed an average of eight hours in any 24-hour period," and for work involving special hazards or heavy strain it becomes an absolute eight in any such period.
- Night time is defined, not assumed. Article 2 calls it "any period of not less than seven hours, as defined by national law," which must include the period between midnight and 05:00. The window is configurable, within a floor.
- A night worker is a classification. Someone who "works at least three hours of his daily working time as a normal course" at night qualifies, so the status is derived from the rota the tool itself produced.
- Breaks attach to length. Article 4 gives a rest break "where the working day is longer than six hours," a different trigger from the Saudi five consecutive hours.
That last pair matters for anyone building once and deploying twice. Five consecutive hours and six hours of working day are not the same test, and a single hardcoded rule satisfies neither jurisdiction properly. The rules belong in configuration.
What that makes the data model
Once the rules are a list, the schema falls out of it. Four things have to be first-class, and in our experience at least two of them usually are not.
- A shift has a span and a worked duration, separately. Breaks sit inside the span and outside the duration. Storing only start and end makes the Saudi twelve hour check impossible to write.
- Rest gaps are computed, not stored. The eleven hour rule is a property of a pair of adjacent shifts, so the validator reads across rows. Any model that validates one shift at a time cannot see it.
- Rules are rows, not code. Jurisdiction, effective date, and the threshold. Ramadan alone proves the point: it is the same rule with a different number for part of the year, applied to some people and not others.
- Every change is an event. Who swapped what, when, and which rule it was checked against. This is the part that earns the tool its keep at an audit, and it is the part that gets cut to ship faster. The same append-only discipline as a purchase request approval workflow, for the same reason.
The same shape appears whenever an internal tool encodes an entitlement rather than a workflow, which is why the leave system and the rota belong in the same conversation. We went through the equivalent list in an employee leave management system and the rules it has to encode, and a rota that cannot see approved leave produces exactly the breach it was bought to prevent.
Hard rules and soft preferences are different features
Most of what managers want from a rota tool is not legal at all. It is fairness: nobody gets three weekends running, the same two people are not always on nights, requests are honoured where they can be. All of that is real and worth building. None of it is a constraint.
Keep the two apart in the code and in the interface. A hard rule blocks the save and names the article it breached. A preference shows a warning and lets the manager proceed, because the manager knows something the tool does not. Collapse the distinction and one of two failures follows: either the tool refuses a rota that was fine, and gets abandoned inside a month, or it waves through a breach because everything is advisory.
What to build first, and what to leave out
An automatic optimiser is the thing everyone asks for and the thing to build last. Shift assignment under constraints is a genuinely hard search problem, and a solver that produces a legal but unpopular rota is worse than a manager with a spreadsheet. Build the validator first and let the manager keep the pen.
- Phase one: import the current rota, run the validator over it, and show what is already breaching. This alone is usually the business case, and it takes days.
- Phase two: swap and cover flows with validation at the point of change. This is where the Thursday morning problem actually gets fixed.
- Phase three: availability and preferences, as warnings.
- Later, if ever: suggested rotas. And when it comes, it suggests rather than decides.
One more input the validator needs on day one: a new joiner has no history, so their first week has no rest gaps to read and no night-worker classification yet. Feed starters in from wherever that record already lives, which is the argument in an internal tool for employee onboarding, scoped to day one.
If the operation is small enough that the rota changes twice a month, the honest answer may be that this is not worth building yet, and a validated spreadsheet is the right tool. That judgement is the same one we set out in internal tools for a small business, and when to stop using Excel.
Honest limits
The Saudi figures above come from the ministry's own English publication and the European ones from the directive text, and both are quoted rather than paraphrased. Neither is legal advice, and the Saudi page prints one article number inconsistently, which is a reminder that an employment lawyer reads the Arabic original before a rule goes into production.
Egypt is deliberately absent. Labour Law No. 14 of 2025 is in force and plainly relevant to anyone building this for an Egyptian employer, but we could not read an official text of it during this research. Secondary summaries disagree with each other on the article numbering and on whether a two hour daily overtime cap exists, so this note asserts no Egyptian article and no Egyptian figure. Get the gazette text before you encode it.
Collective agreements, sector rules and derogations also sit on top of all of the above and can tighten or relax it. That is another argument for rules as configuration: the one thing you can predict about these numbers is that somebody will hand you a different set.
The short version: a shift scheduling tool is a validator with a calendar attached. Model the span separately from the worked hours, compute rest gaps across adjacent shifts, keep the thresholds in rows with effective dates, log every change against the rule it was checked on, and leave the optimiser until the validator has been right for six months. Start with the rota you already have and let the tool tell you what is wrong with it.
Describe it. We build it.
Seven or twelve days, pay on delivery, a year of maintenance included. Bring the problem, not a spec.
Book a meetingRead next
An event registration and ticketing system, and when to build one
An event registration and ticketing system is a fee decision before it is a software decision. The published platform fees, and what owning the data means.
ReadAn AI voice agent for appointment booking, scoped honestly
An AI voice agent for appointment booking: the transport choice, the disclosure the EU AI Act now requires, the calendar write problem, and the handoff rule.
Read