longestRun
Signature
Section titled “Signature”longestRun(log: DutyEntry[], window: Interval, statuses: string[]): { interval: Interval; duration: string; } | nullReturn the longest unbroken stretch a duty log spends in any of statuses inside a window.
- A stretch is a run of touching entries whose statuses are all in
statuses; another status or an unlogged gap ends it. Each run is cut towindow(half-open) before it is measured. - On a tie the earlier stretch is returned.
intervalis in UTC instants ending in “Z”;durationis an exact ISO 8601 duration with hours as the largest unit.- Returns
nullwhen no stretch falls inside the window, which is also the sentinel: when the log failsisValidDutyLog, whenwindowis not a validInterval, and whenstatusesis not an array of strings.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
log | DutyEntry[] | the duty log, ordered and non-overlapping |
window | Interval | { start, end } record of ISO 8601 instant strings to search inside |
statuses | string[] | the statuses a stretch is made of |
Returns
Section titled “Returns”{ interval, duration } of the longest stretch, or null when there is none or on invalid input
Members
| Member | Type | Description |
|---|---|---|
interval | Interval | The stretch, as UTC instants ending in “Z”, cut to the window. |
duration | string | Its length, an exact ISO 8601 duration with hours as the largest unit. |
Related types
Section titled “Related types”Examples
Section titled “Examples”import { longestRun } from "@northguild/gmt/duty/calculate";
longestRun([{ status: "driving", start: "2024-01-01T00:00:00Z", end: "2024-01-01T03:00:00Z" }, { status: "onDuty", start: "2024-01-01T03:00:00Z", end: "2024-01-01T04:00:00Z" }, { status: "driving", start: "2024-01-01T04:00:00Z", end: "2024-01-01T08:00:00Z" }], { start: "2024-01-01T00:00:00Z", end: "2024-01-02T00:00:00Z" }, ["driving"]) // { interval: { start: "2024-01-01T04:00:00Z", end: "2024-01-01T08:00:00Z" }, duration: "PT4H" }