# Shifts, legal settings, meals and quality

You will know what a shift is and what the grid checks about it, which settings are set by law and which by comfort, how a due break is calculated and deducted from effective work, and how a scenario file pins its own values.

## A grid is made of shifts

A timeslot is a **shift**: a real slice of work on which someone is assigned, there is no other kind of timeslot ([decision 0037](repo:docs/decisions/0037-une-grille-est-toujours-des-vacations.md)). The event projects its hours into shifts through its [templates](modele-des-donnees.md#le-générateur-de-créneaux-et-ses-gabarits); a grid carries a single variant of each shift and any stand sits on any open timeslot ([decision 0029](repo:docs/decisions/0029-retrait-des-familles-de-relais.md)).

### What the grid check reports

`CreneauGridService` (`GET /api/creneaux/controle`) sorts its anomalies into errors (malformed grid, or guaranteeing a hard-rule breach) and warnings (suspicious, never a refusal). Two concern duration: `VACATION_TROP_LONGUE` (warning: the shift exceeds `dureeVacationMaxMinutes`, 6 h by default, the threshold of art. [L3121-16]; it will contain a break to relay, check that a stand colleague holds a seat then or cut the day) and `REPOS_QUOTIDIEN_IMPOSSIBLE` (error: it exceeds `1440 − reposQuotidienMinimalMinutes`, any assignment would produce a hard breach). A shift over 6 h is therefore not refused: it is legal if a colleague relays it. The threshold lives in `ParametresLegaux`: it is an event rule judged on the grid however it was written.

### Overlap is a demand peak

Two consecutive shifts may overlap for a handover: two seats then exist on the same stand, and two overlapping shifts of the same day are never an anomaly. It is also the main source of peaks: **if all stands hand over at the same instant, the number of seats to fill doubles at that precise moment**, which may exceed the available headcount: the problem is infeasible by construction, with no shortage of staff members at all. The lever is to stagger handovers. The feasibility analysis (`GET /api/feasibility`) **does not see this peak**: an optimistic estimate aggregated per day, without competences, counting a minor only where they can sit; it may answer "feasible" while the solver does not bring the hard score to zero. After a solve, the reliable signal is the **actual hard score**, not `feasible` alone.

### Covering a stand during the meal

Three ways to handle midday: the stand closes (no shift over the window, or a closure plage), full headcount during the break (an ordinary shift over the window), or reduced headcount (a stand opening plage naming its own headcount, *Stands › Hours*). There is no "meal relay" flag on the shift any more: it is the stand that knows how many people it needs at midday (`Creneau.siegesSegment`, never fewer than one seat). A full shift over the meal window is to be handled carefully on a tight scenario: one more team per break, concentrated on the same window, is exactly the peak described above.

### A single seat count

The number of seats of an open segment (at least one) is `Creneau.siegesSegment`, and a stand's busiest segment on a timeslot is `Creneau.siegesSimultanes`: seat generation, feasibility, fragility and `eviterRoulementStandsPremium` read these two methods, so what the solver fills and what the screens announce cannot be two different numbers.

## The legal settings

`ParametresLegaux` is a problem fact stored **per edition**, set through `GET` and `PUT /api/parametres/legal` (`legal` section, with `organisation`, `notifications` and `instance`; `GET /api/parametres` returns the four). It carries the law's ceilings and the rules the organisation gives itself:

| Field | Default | Origin |
| --- | --- | --- |
| `dureeHebdomadaireMaxMinutes` | 48 h | French Labour Code (*Code du travail*) art. [L3121-20], public policy. Constraint `dureeHebdomadaireMax`, for adults |
| `dureeHebdomadaireMaxMineurMinutes` | 35 h | Art. [L3162-1]; art. [D4153-3] for ages 14 to under 16. Constraint `dureeHebdomadaireMax`, for minors |
| `reposQuotidienMinimalMinutes` | 11 h | Art. L3131-1 |
| `dureeVacationMaxMinutes` | 6 h | Threshold of the grid check (art. L3121-16) |
| `dureePauseMinutes` | 30 min | Legal floor of 20 min, see [the legal break](#la-pause-légale) |
| `coupureRepasMinutes`, lunch and evening windows | 60 min; 12:00-14:00; 19:00-21:00 | Organisation rule, see [the meal break](#la-coupure-repas) |
| `heureDebutSoiree` | 20:00 | Start of the evening for the fairness reading, an organisation rule. A minor's legal night remains carried by `Creneau` |

`ParametresValidator` refuses anything crossing a public-order ceiling, with the article founding it (beyond 48 h or 35 h, a break under 20 minutes); a value more protective than the law stays free. A negative daily rest, a zero shift duration, a meal window without both bounds and a missing `heureDebutSoiree` ("no evening" would empty a fairness-screen column without a word) are also refused. The other legal thresholds are code constants (`LegalConstraints`, `PlafondsLegauxMajeurs`): daily duration (10 h), continuous work (6 h), weekly rest (35 h), six days a week; they are public-order minima and maxima an administrator has no reason to relax.

Two counting conventions. **Week attachment**: a timeslot is attached entirely to the ISO week of its start date (`Creneau.semaineIso`); a Sunday 20:00-to-midnight timeslot counts in the week that ends, a conservative convention as long as night timeslots are short. **Opening span and effective work**: a timeslot's duration measures a span, whereas the articles concern effective work; the model represents no break inside a timeslot, so breaks are **gaps between two timeslots** or relays. The two weekly constraints group the seats by animateur and by **day**, then days by ISO week, and penalise the overrun pro rata to the excess minutes; the per-day level serves to deduct the due breaks, computed per day.

### The legal break

A due break is taken as **a gap** of at least `dureePauseMinutes` or **a relay** by a colleague of the **same stand**; with neither, it is a **hard breach**: the reasoning and the deduction from effective work are in [legal rules and breaks](regles-legales-et-pauses.md#la-pause-légale--un-trou-ou-un-relais) ([decision 0048](repo:docs/decisions/0048-une-seule-regle-de-pause.md)). The duration is **a single parameter**, `dureePauseMinutes` (`parametres.legal` section of a scenario): 30 minutes by default, floor of 20 (art. L3121-16), raised to 30 for a minor (art. L3162-3) by `ParametresLegaux.dureePauseMinutes(mineur)`.

**The computation is written once**: `PauseSurPoste.dues(postes, parametres)` returns the breaks of an (animateur, day) pair: a sequence of `L` minutes beyond the ceiling `cap` owes `ceil((L − cap) / (cap + pause))`, the k-th at the latest when the sequence reaches its k-th ceiling. The solver, the break report, the PDF and the ICS feed read this method. **The deduction is unconditional**: a due break is rest (art. L3121-1), subtracted from the span for the ceilings, the hours report, fairness, Needs and KPIs (`EffectiveWork`). A 14:00-midnight day is worth 9 h 30 of effective work; 13:00-midnight is worth 10 h 30 and stays refused.

## The meal break

`FenetreRepas` is a problem fact, **one per declared window** (start, end, required break duration), read by `coupureRepasObligatoire` and `coupureRepasPlacementPrefere` ([the rule](regles-legales-et-pauses.md)): a day straddling midday *and* the evening produces **one breach per window**, each naming its hours. The values live in `ParametresLegaux` (`coupure_repas_*` columns), projected by `FenetreRepas.from(...)`; it is not a legal obligation but the organisation's rule, judged on any grid; a [consigne](horaires-et-fenetres-des-stands.md#restater-la-coupure-repas-pour-une-date) can restate them for its date. **A scenario is judged on the windows it declares**, not those of the database. A window is set aside if its bounds are missing, if it is empty, inverted, of zero duration, or **shorter than the break it demands**: a rule no assignment can reach would penalise an entry rather than a planning.

## The quality settings

`ParametresQualite` is a `record` (a problem fact is immutable: the solver reads it thousands of times a second) for the thresholds that set **comfort**, not the law. They are **stored per edition** (`GET` and `PUT /api/parametres-qualite`); the `planning.contraintes.*` block is only the default of an edition that never opened the screen. A setting that makes a rule inert is a legitimate way to say "not here". `SolveRunner.prepareProblem` systematically overwrites this fact with the edition's value: a caller cannot loosen a threshold by sending it in its payload.

| Field | Default | Constraint reading it |
| --- | --- | --- |
| `maxEmplacementsDistinctsParJour` | 3 | `limiterEmplacementsParJour` |
| `heureServiceTardif`, `heureServiceMatinal`, `reposSouhaiteApresServiceTardifMinutes` | 22h, 10h, 720 | `eviterFermeturePuisOuverture` |
| `typologiesDistinctesMax` | 2 | `limiterTypologiesDistinctesParAnimateur` |
| `joursConsecutifsMax` | 8 | `maxJoursConsecutifsTravailles`, at all its levels |
| `vitesseMarcheKmH`, `facteurDetour`, `toleranceTrajetMinutes` | 4, 1.3, 5 | `trajetInsuffisantEntrePostes` |
| `toleranceArriveeGroupeeMinutes` | 30 | `arriveeGroupee` |
| `placementRepas` | `FIN_MIDI_DEBUT_SOIR` (per edition) | `coupureRepasPlacementPrefere` |

A few notes on reading it:

- an hour left **empty** reads as absent, not as midnight: that is how a deployment neutralises `eviterFermeturePuisOuverture`; a zero desired rest, or at most the legal floor, makes the rule inert (only what it asks beyond the legal rest is penalised);
- `typologiesDistinctesMax` counts over the whole edition, not the day, and polyvalent staff are exempt;
- `joursConsecutifsMax` is 8 because it is a feasibility condition more than a comfort: the rule requires a rest day in each window of `max + 1` days; too tight a ceiling with the hard form leaves empty seats, and no weight buys what arithmetic forbids ([decision 0045](repo:docs/decisions/0045-le-niveau-de-la-regle-des-jours-d-affilee.md));
- `ParametresValidator` refuses what would mean nothing: a ceiling below 1, a negative desired rest, a non-positive walking speed, a group-arrival tolerance outside 0 to 240 minutes.

## Scenario sections

A scenario file can set its own parameters under `parametres:`: `legal` and `organisation` (the quality thresholds). The solve budget is no longer part of it: an old file carrying `parametresSolveur` is read and ignored, the import saying so. For `legal`, only the fields to override are given and the others keep the **Java class's** default, never the database value; a file without the section takes the parameters of the edition importing it. In `organisation`, the two hours are read as is (a section naming neither describes an edition where `eviterFermeturePuisOuverture` says nothing) and omitted numbers take their default.

Removed sections and keys are **refused by name** rather than ignored (`ScenarioBinder`): `parametresDecoupage` and `decoupageAuto` (a span grid read as shifts would give 14-hour days without a word) and the `pauseSurPoste`, `pauseMinimaleEntreVacationsMinutes`, `dureePauseMajeurMinutes`, `dureePauseMineurMinutes` keys of `parametres.legal`, each with its replacement. The same mechanism refuses any unknown key and a `schemaVersion` newer than the one the version reads ([scenario-yaml](scenario-yaml.md)).

<!-- Links to Légifrance. Each reference points to the search by article
     number, which always resolves to the version in force: a LEGIARTI
     identifier designates a dated version, and silently goes stale. -->
[D4153-3]: https://www.legifrance.gouv.fr/search/code?tab_selection=code&searchField=NUM_ARTICLE&query=D4153-3
[IDCC 1518]: https://www.legifrance.gouv.fr/conv_coll/id/KALICONT000005635177
[L3121-16]: https://www.legifrance.gouv.fr/search/code?tab_selection=code&searchField=NUM_ARTICLE&query=L3121-16
[L3121-20]: https://www.legifrance.gouv.fr/search/code?tab_selection=code&searchField=NUM_ARTICLE&query=L3121-20
[L3162-1]: https://www.legifrance.gouv.fr/search/code?tab_selection=code&searchField=NUM_ARTICLE&query=L3162-1
