# scheduleDeviation

Industry: Transport

## Signature

```ts
scheduleDeviation(planned: string, actual: string): string
```

Measure how far an actual time is from its plan: positive when late, negative when early.

- Every mode publishes a plan and records what happened, and measures the gap the same way. This is that gap; `classifyPunctuality` judges it against a tolerance.
- **Exact elapsed time**, as an ISO 8601 duration with hours as the largest unit, so the value never depends on a calendar or a wall clock. A delay across a fall-back night is `PT1H`, never the `PT0S` a wall-clock subtraction reads; across a spring-forward it is `PT1H`, never `PT2H`. Two days late is `PT48H`, not `P2D`.
- **Signed:** `actual` after `planned` is positive (late), before it negative (`"-PT5M"`, early), and equal is `"PT0S"`.
- Both arguments are exact instants (`Z`/offset) with no annotation of any kind. The offset each is written in does not matter. To show a schedule's local time, use `etaAtZone`.
- Returns `""` on invalid input, including a zoneless wall time, which is not a moment.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `planned` | `string` | ISO 8601 instant string of the planned time |
| `actual` | `string` | ISO 8601 instant string of the actual (or compared) time |

## Returns

ISO 8601 duration from planned to actual, negative when early, or "" on invalid input

## Examples

```ts
import { scheduleDeviation } from "@northguild/gmt/transport/compare";

scheduleDeviation("2024-06-15T10:00:00Z", "2024-06-15T10:14:00Z") // "PT14M"
```

## Source

[transport/compare/scheduleDeviation.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/transport/compare/scheduleDeviation.ts)
