qualifyingRestPairs
Signature
Section titled “Signature”qualifyingRestPairs(log: DutyEntry[], spec: { statuses: string[]; minimum: string; pair: PairSpec; }): RestPair[]Return every paired rest in a duty log: two separate rests that together count as one, because they meet all three floors of spec.pair.
- A pair is three constraints, not two integers: with
{ eachAtLeast: "PT2H", oneAtLeast: "PT7H", combinedAtLeast: "PT10H" }, 7.5 + 2.5 hours and 8 + 2 qualify, and 6 + 4 does not. - Rests are runs of touching entries in
spec.statuses. Two rests in a row pair; either may be the longer. - A rest of
spec.minimumor more is a full rest on its own: it pairs with nothing, and no pair spans it. A rest shorter thaneachAtLeastis neither half of a pair nor a break between two. - Pairs chain: rests of 7, 3 and 7 hours give two pairs, (7, 3) and (3, 7).
- Intervals are UTC instants ending in “Z”, in log order.
[]is both a legitimate result and the sentinel: returned when the log failsisValidDutyLog, whenspecis not an object, whenstatusesis not an array of strings, and whenminimumor a floor ofpairis not a positive ISO 8601 duration of exact time.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
log | DutyEntry[] | the duty log, ordered and non-overlapping |
Options
Section titled “Options”spec
the statuses a rest is made of, the length of a full rest, and the pair’s floors
| Option | Type | Default | Description |
|---|---|---|---|
statuses | string[] | Required | The statuses a rest is made of. Touching entries in any of them are one rest. |
minimum | string | Required | The length of a full rest, a positive ISO 8601 duration of exact time ("PT10H"). A rest this long or longer is not half of a pair. |
pair | PairSpec | Required | The three floors the two rests must meet. |
Returns
Section titled “Returns”the pairs as { first, second } records, or [] on invalid input
RestPair
Section titled “RestPair”Two rest periods that satisfy a PairSpec, in the order they were taken.
import type { RestPair } from "@northguild/gmt";| Member | Type | Description |
|---|---|---|
first | Interval | The earlier period, as UTC instants. |
second | Interval | The later period, as UTC instants. |
Related types
Section titled “Related types”Examples
Section titled “Examples”import { qualifyingRestPairs } from "@northguild/gmt/duty/calculate";
qualifyingRestPairs([{ status: "sleeper", start: "2024-01-01T00:00:00Z", end: "2024-01-01T07:30:00Z" }, { status: "work", start: "2024-01-01T07:30:00Z", end: "2024-01-01T11:30:00Z" }, { status: "off", start: "2024-01-01T11:30:00Z", end: "2024-01-01T14:00:00Z" }], { statuses: ["off", "sleeper"], minimum: "PT10H", pair: { eachAtLeast: "PT2H", oneAtLeast: "PT7H", combinedAtLeast: "PT10H" } }) // [{ first: { start: "2024-01-01T00:00:00Z", end: "2024-01-01T07:30:00Z" }, second: { start: "2024-01-01T11:30:00Z", end: "2024-01-01T14:00:00Z" } }]