# Workforce

Industry: Workforce

Workforce is people's working time, for any crew, shift or rota. It is counted in duty days that need not start at midnight, in rolling windows that slide across the log, and in rests that may be split in two. A working-time regime is a set of numbers, and the caller states every one of them. This layer reads a duty log against those numbers, and holds none of its own.

## What these functions solve

- **A duty day does not start at midnight.** An operator names the time its day starts and the zone it is read in. [`dutyDayFor`](/gmt/reference/workforce/calculate/dutyDayFor/) returns the day an instant falls in, so a log is grouped by the operator's day and never by the calendar's. See [guide](/gmt/guides/industries/workforce-hours-of-work/), [scenario](/gmt/scenarios/duty-day-is-not-midnight/).
- **A sliding window is not a calendar day.** A rule that asks for a rest in any stretch of a given length looks at every such stretch, not at each day on its own. [`evaluateDutyLog`](/gmt/reference/workforce/calculate/evaluateDutyLog/) checks every rule at one instant, and [`dutyTotals`](/gmt/reference/workforce/calculate/dutyTotals/) adds up the time spent in the statuses you name inside a window. See [guide](/gmt/guides/industries/workforce-hours-of-work/), [scenario](/gmt/scenarios/sliding-window-not-calendar-day/), [mistakes](/gmt/mistakes/workforce/).
- **Two short rests may count as one, or may not.** A regime that lets a rest be split sets a floor for each part and for the two together. [`qualifyingRestPairs`](/gmt/reference/workforce/calculate/qualifyingRestPairs/) finds the pairs that meet all of the floors you state, so a pair that meets only two of them is not counted. See [scenario](/gmt/scenarios/paired-rest-that-does-not-qualify/), [mistakes](/gmt/mistakes/workforce/).
- **A log has to be checked before it is counted.** A log with overlapping entries, or an entry that ends before it starts, gives a total that looks right and is not. [`isValidDutyLog`](/gmt/reference/workforce/validate/isValidDutyLog/) tells whether every function in this layer accepts the log. See [guide](/gmt/guides/industries/workforce-hours-of-work/), [mistakes](/gmt/mistakes/workforce/).

Start with the guide: [Workforce: Hours of Work](/gmt/guides/industries/workforce-hours-of-work/).

## Its own functions

### [`workforce`](/gmt/reference/workforce/)

**[calculate](/gmt/reference/workforce/calculate/)**

- [`dutyDayFor`](/gmt/reference/workforce/calculate/dutyDayFor/): Return the operator-designated day an instant falls in: from the most recent `dayStartTime` in `timeZone` at or before the instant, up to (not including) the next one.
- [`dutyTotals`](/gmt/reference/workforce/calculate/dutyTotals/): Return the time a duty log spends in any of `statuses` inside a window, as an exact ISO 8601 duration.
- [`dutyViolations`](/gmt/reference/workforce/calculate/dutyViolations/): Return every violation of a set of hours-of-work rules inside a range, each with the window that failed it: the record over a month, not the check before dispatch.
- [`evaluateDutyLog`](/gmt/reference/workforce/calculate/evaluateDutyLog/): Evaluate every hours-of-work rule over a duty log at one instant, and report each one whether or not it binds.
- [`longestRun`](/gmt/reference/workforce/calculate/longestRun/): Return the longest unbroken stretch a duty log spends in any of `statuses` inside a window.
- [`qualifyingRestPairs`](/gmt/reference/workforce/calculate/qualifyingRestPairs/): 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`.
- [`qualifyingRests`](/gmt/reference/workforce/calculate/qualifyingRests/): 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.

**[validate](/gmt/reference/workforce/validate/)**

- [`isValidDutyLog`](/gmt/reference/workforce/validate/isValidDutyLog/): Validate whether a value is a duty log every `workforce/` function accepts.

## Guides

- [Workforce: Hours of Work](/gmt/guides/industries/workforce-hours-of-work/): Evaluate hours-of-work rules over a duty log with the workforce layer — caps, windows, breaks, rests, quotas and patterns, every number yours — and read the day the operator designates, not local midnight.

## Scenarios

- [A Paired Rest That Does Not Qualify](/gmt/scenarios/paired-rest-that-does-not-qualify/): Two rests may count as one when each is at least 2 hours, one at least 7 and both together at least 10. Checking two whole numbers passes 6 + 4 and fails 7.5 + 2.5 — both wrong.
- [A Sliding Window Is Not a Calendar Day](/gmt/scenarios/sliding-window-not-calendar-day/): A rule asks for 10 hours of rest in any 24. Each calendar day of the log holds 10, so a per-day check passes, but the 24 hours ending at 06:00 hold 4.
- [The Duty Day Is Not Midnight](/gmt/scenarios/duty-day-is-not-midnight/): An operator's day starts at 04:00 in São Paulo. Grouping a driver's log by local midnight puts a 03:30 entry in the wrong day, and an entry logged in Tokyo in the wrong day again.

## Mistakes

- [Workforce](/gmt/mistakes/workforce/): Common mistakes when checking a duty log against hours-of-work rules with GMT's workforce/ namespace.
