qualifyingRests
Signature
Section titled “Signature”qualifyingRests(log: DutyEntry[], spec: { statuses: string[]; minimum: string; }): Interval[]Return every rest of at least minimum in a duty log: the runs of touching entries in any of spec.statuses that last that long.
- A run is ended by another status or an unlogged gap, never by a change between two of
statuses: an off period running straight into a sleeper-berth period is one rest. - The whole log is read. Intervals are UTC instants ending in “Z”, in log order.
- For two shorter rests that count together, use
qualifyingRestPairs. []is both a legitimate result and the sentinel: returned when the log failsisValidDutyLog, whenspecis not an object, whenstatusesis not an array of strings, and whenminimumis 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 and the shortest that counts
| 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 shortest rest returned, a positive ISO 8601 duration of exact time ("PT10H"). |
Returns
Section titled “Returns”the rests’ { start, end } records, or [] on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { qualifyingRests } from "@northguild/gmt/duty/calculate";
qualifyingRests([{ status: "off", start: "2024-01-01T00:00:00Z", end: "2024-01-01T10:00:00Z" }, { status: "work", start: "2024-01-01T10:00:00Z", end: "2024-01-01T16:00:00Z" }, { status: "off", start: "2024-01-01T16:00:00Z", end: "2024-01-01T23:00:00Z" }], { statuses: ["off"], minimum: "PT10H" }) // [{ start: "2024-01-01T00:00:00Z", end: "2024-01-01T10:00:00Z" }]