dutyTotals
Signature
Section titled “Signature”dutyTotals(log: DutyEntry[], window: Interval, statuses: string[]): stringReturn the time a duty log spends in any of statuses inside a window, as an exact ISO 8601 duration.
- The interval algebra of CORE-6: the entries in
statusesare merged, each run is cut towindow(half-open), and what is left is summed. An entry that crosses the window’s edge counts only its part inside. - Hours are the largest unit, as
sumIntervalswrites it:"PT49H30M", never days. []asstatuses, an empty log or an empty window gives"PT0S".- Returns
""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 total inside |
statuses | string[] | the statuses whose time is totalled |
Returns
Section titled “Returns”ISO 8601 duration string, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { dutyTotals } from "@northguild/gmt/duty/calculate";
dutyTotals([{ status: "driving", start: "2024-01-01T10:00:00Z", end: "2024-01-01T15:00:00Z" }, { status: "onDuty", start: "2024-01-01T15:00:00Z", end: "2024-01-01T17:00:00Z" }, { status: "driving", start: "2024-01-01T17:00:00Z", end: "2024-01-01T20:00:00Z" }], { start: "2024-01-01T00:00:00Z", end: "2024-01-02T00:00:00Z" }, ["driving"]) // "PT8H"