Skip to content

qualifyingRests

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 fails isValidDutyLog, when spec is not an object, when statuses is not an array of strings, and when minimum is not a positive ISO 8601 duration of exact time.
ParameterTypeDescription
logDutyEntry[]the duty log, ordered and non-overlapping

spec

the statuses a rest is made of and the shortest that counts

OptionTypeDefaultDescription
statusesstring[]RequiredThe statuses a rest is made of. Touching entries in any of them are one rest.
minimumstringRequiredThe shortest rest returned, a positive ISO 8601 duration of exact time ("PT10H").

the rests’ { start, end } records, or [] on invalid input

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" }]
log
output 

duty/calculate/qualifyingRests.ts