# Hours, consignes and effective windows

You will know how a stand's hours become opening windows, how an edition's consigne (an official order, such as an arrêté, relayed to the whole event) closes them again without destroying anything, why the past is no longer rewritten, and what a seat carries when its timeslot is open only in pieces.

## Three states per day for a stand

Each day is decided independently. A day cannot carry both closures and openings: the write refuses it, which avoids arbitrating a conflict at solve time.

| What the stand declares that day | Reading |
| --- | --- |
| Neither closure nor opening | Open without restriction, the overwhelmingly common case |
| At least one closure | Open by default, closed only on the listed windows. The solve subtracts the union of the closures that overlap the timeslot: a closure in the middle leaves two open segments |
| At least one opening | **Closed by default**, open only on the listed windows. This is the case of a stand that opens on a few timeslots only: one opening instead of one closure per timeslot |

An empty `heureFin` means "until closing": the window runs to the end of the evaluated timeslot. A window cannot cross midnight, unlike a timeslot; a window dated day D+1 is read only by a timeslot that really crosses midnight, each day covered being read in its own mode.

## Headcount is carried by the window

A stand whose load varies during the day (4 people in the morning, 5 in the evening) stays **a single stand**: each opening window carries its `effectif`. Empty, it inherits `effectifMin`, so that a window that names none generates what it generated before the field existed. The minimum is what a stand requires at its quietest hour: applying it to the peak would understaff it.

Saving a stand from the entry grid **derives its two bounds from its cells**: `effectifMin` is the smallest value entered, `effectifMax` the largest, both ways (a stand declared at 5 with no cell above 2 comes out at 2). The record stays the place to set a capacity the grid does not show. A window headcount cannot exceed `effectifMax` (validator and form refuse it): otherwise generation would make mandatory more seats than the stand is declared able to hold.

A timeslot straddling two windows of different headcounts produces **two groups of seats**, each carrying its segment's [effective window](#fenêtre-effective). Where two windows overlap, the **highest** headcount applies. Contiguous slices of the same headcount are merged again. `segmentsOuverts` is the primary computation; `segmentsOuvertsMinutes` is its projection (pure opening geometry).

### Two fields the solver does not read

`effectifMax` bounds entry (stand validator, a consigne's opening, derivation from the grid) and nothing else: a timeslot's seat count is its window's headcount, failing that `effectifMin`, and no rule caps the number of staff members on a stand. `manager` is a record label (filter, CSV import column, comparison between editions) that no rule reads: a manager is scheduled like the others and counts in the ceilings, legal ones included. `mineurNecessiteEncadrementMajeur` is off by default; on, it requires a scheduled adult on the same stand and timeslot, manager or not.

## Opening hours are a list of dated plages

Since 4.0, a stand carries only a **list of plages** (`PlageStand`): a day, hours, a mode (`OUVERTURE` or `FERMETURE`), a headcount for an opening, a reason ([decision 0104](repo:docs/decisions/0104-les-horaires-d-un-stand-sont-une-liste-de-plages-datees.md)). No recurring rule is stored: "every Monday 10-12" is a **generator** that writes one plage per Monday, and the plage is what is read afterwards. The resolution (`HoraireStandResolver`) lays these plages as effective windows, on which the consigne then applies; it always yields **a single mode per day**, so the three states at the top of this page are all that segment computation, constraints and exports need to know.

**A plage's origin is stored**: a plage unfolded from the model carries `depliee` (column, YAML file key), a hand-typed one does not. The resolution does not use it, but whatever reads "where this day comes from" does: a day only the model explains is the stand's normal regime (`REGLE`), not an exception, so a consigne's preselection finds the open stands. Changing the model removes exactly the marked plages; a hand-typed plage stays, even identical. **Accepted cost**: a day added to the event afterwards has no plage but receives the stand's model if it keeps one (without it, the stand is open all day there); a daily schedule over a long edition makes one line per day and per window.

## The consigne, plages written on the stands

A prefectoral order (heatwave, storm) closes a time band for **all** stands on a few dates: neither a stand rule nor a dated exception, the decision comes from outside and must be lifted without rewriting anything. It is an **edition consigne** ([decision 0043](repo:docs/decisions/0043-consigne-d-edition-fermer-une-bande-sans-rien-detruire.md)). Since 4.0 ([decision 0125](repo:docs/decisions/0125-la-consigne-s-ecrit-en-plages-datees.md)), setting it **writes dated plages** marked `consigne` on each stand of its date, and lifting it removes exactly those; the resolution reads only plages, through a single entry point, `StandService.resolve` (a caller reading plages itself would silently staff the closed band: `ConsigneCoucheStructurelleTest` refuses it). A consigne carries, per date: a **forbidden band** (mandatory start, optional end meaning "until midnight"), a mandatory **reason**, the name of the originating **preset** (stored on the edition and copied at duplication, unlike consignes), **default compensation windows**, **openings** (a stand, a window, an optional headcount) and the timeslots **added** to the grid.

Three rules, written as plages on each stand of a date under consigne:

1. **The band closes all stands**, with a closure above their own plages, and closes only that: a 14h-20h becomes an 18h-20h.
2. **The timeslots the consigne added belong to nobody's hours**: a closure on each, otherwise a stand open by default would be staffed on an evening nobody chose for it.
3. **An opening is an extension chosen stand by stand**: one opening per window, outside the band; the stand opens on it in addition to its hours, even where its plages close it, at the headcount entered, failing that the highest headcount it loses in the band, failing that its minimum (the higher of the two where a window overlaps another).

**How the day reads.** The consigne's plages are read *above* the stand's: its closures remove their extent from the stand's own hours, never from its own openings, which are added. The day comes out **restated whole** by `HoraireStandResolver` (explicit openings, or a whole-day closure if nothing remains): a single mode per day, and nothing downstream knows the consigne. The inherited headcount is computed at setting and written on the plage: setting the consigne again recomputes it.

**Lifting removes exactly the consigne's plages.** A consigne plage edited by hand loses its mark and stays at lifting, like a plage added by hand that day. Setting or lifting changes the stamp of every stand of the edition: a record opened before is refused at saving (409) rather than rewrite the day without the band or put it back after the lifting. A scenario file never carries these plages: it carries the consigne, and the import rewrites them; an edition copy does not take them.

**The grid is touched only additively**: a window no timeslot covers (20h-22h after a day ending at 20h) adds the missing timeslot, marked as added by the consigne, and an opening must require it. Modifying a consigne keeps an added timeslot, with its seats, as long as a window exactly requires it. **Nothing else is destroyed**: nominal timeslots keep id, seats and locks; a stand closed over a whole timeslot generates no seat there, closed over part of it generates the seats of the rest. At lifting, stands recover their hours and only the added timeslots go, with their seats (the next publication announces their removal); the [published plan's stability](plan-verrous-et-publication.md#le-plan-publié) does the rest: the holder of a 14h-20h stays on the 18h-20h during the alert and gets their afternoon back at lifting.

**The past stays intact**: setting, modifying and lifting refuse a past or current date; a date already worked keeps its consigne forever. **Accepted limits**: the band is mandatory (a consigne without a band is a template); one band per day; availabilities stay per day; night and rest rules read the whole timeslot, not the effective window, which closes late windows to minors; an evening window extending the afternoon needs two people per seat as long as the evening meal break forbids chaining 18h-20h and 20h-22h.

### Restating the meal break for a date

The meal break is the organiser's rule, not the Labour Code's ([meals and breaks](parametres-legaux-et-qualite.md#la-coupure-repas)). A consigne can therefore set, for its date only, other midday and evening windows and another break duration, with a mandatory justification. The solver receives two kinds of `FenetreRepas`: the edition's, which carry the dates where they step aside, and the consigne's, dated (`FenetreRepas.appliesTo(date)`). Lifting the consigne removes its windows; the edition's legal parameters were never written; legal ceilings cannot be overridden.

## The past is frozen

Every solve, full or incremental, from the screen or through MCP, takes from the saved plan the seats of timeslots already begun and pins them, whatever their state ([decision 0044](repo:docs/decisions/0044-le-passe-est-fige.md)). The holder is kept even if they have since declared the day unavailable; a deleted holder leaves the seat empty; an empty past seat is pinned all the same. A timeslot is *begun* if its date is past, or if it is today and the seat's effective start is reached (a timeslot crossing midnight belongs to its start date); "today" is the day-of clock's (the machine in production, or the date frozen from Settings › Instance under `quarkus:dev` or with `HORLOGE_SIMULEE_AUTORISEE=true`). These seats **count** in the rules linking days (daily rest, weekly durations, consecutive days, breaks, "close late then open early") but are **never blamed**, and a replanning's scope never reopens them.

**The past is no longer edited by hand either**: gestures that rewrite a seat without the solver ("Assign" and "Apply" of "Replace", `modifier_affectation`, accepting a swap, a repair) refuse a seat whose timeslot has begun: "This timeslot has already begun: the past can no longer be modified." (`400` on REST, business refusal on MCP; `FrozenPast.PAST_SEAT_REFUSAL`).

### The past is frozen to the minute

A repair, a "Place" or a "Mark absent" on the seat of a timeslot **under way** is not refused ([decision 0066](repo:docs/decisions/0066-le-passe-est-fige-a-la-minute.md)): the write **splits the seat at "now"**, the current minute of the day-of clock, into two real seats:

- the origin is cut short at that minute (`heureFinEffective`) and keeps its holder: the history says who held 9:00 – 9:20;
- the continuation covers the rest of the timeslot (`heureDebutEffective`), carries `suiteDe` (the origin's identifier, `poste_affectation.suite_de`) and receives the write; its identifier is derived: `<origine>~HHmm`.

An **empty** seat is not split: placing someone there **trims** it (same line, start moved to "now", identifier `<seat>~HHmm` without `suiteDe`); only an already finished seat stays refused. A split seat stays **one** seat:

| Where | What the split changes |
| --- | --- |
| Per-seat generation, premium stand crew | Nothing: the continuation is not an extra seat |
| Rebuild (restart, incremental) | `SeatSplit.restore` replays the split or trimmed cells of the persisted plan; the solver reopens only the continuation |
| Snapshots, scenario export | The continuation and its `suiteDe` are captured and restored with the plan; the export omits them (a scenario describes the seats to fill) |
| "New since this morning" | The continuation is a cell the published plan did not have: its empty seat is new |

**Nothing to plan**: a solve whose seats are all past is refused rather than produce an empty plan at zero hard; if past seats stayed empty, the solve takes place and its result carries `postesPassesVides`, announced as a warning. `PASSE_FIGE=false` turns the whole rule off (pinning, gesture refusals, refusal of a solve with no future), for an acceptance run replaying an old edition; it is off by default under the test profile.

## Effective window

A seat coming from a partial segment carries a window narrower than its timeslot. It is **not a sub-timeslot**: the foreign key points to a real, persisted timeslot, the window lives on the seat, and the accessors fall back on the timeslot when the override is absent. The rules that read the window and those that read the whole timeslot are distinguished in [the solver rules](pourquoi-ces-regles.md).
