# timeToCutoff

Industry: Transport

## Signature

```ts
timeToCutoff(now: string, cutoff: string): string
```

Measure the time left until a cut-off, negative once it has passed.

- Exact elapsed time as an ISO 8601 duration with hours as the largest unit, so the value never depends on a calendar: across a fall-back night, 17:00 to 17:00 the next day is `PT25H`. It is `PT0S` at the cut-off itself, where `isPastCutoff` turns `true`.
- Negative (`"-PT1H"`) once `now` is after the cut-off: how late it is.
- `now` is an exact instant (`Z`/offset) with no annotation of any kind. `cutoff` is the zoned string `cutoffAt` returns, `<date>T<time>±HH:MM[Zone]`: an offset (or `Z`), then one time zone bracket that agrees with it (the critical `[!Zone]` too), and nothing after. A bare instant, an offset-less wall time, an offset bracket (`[+02:00]`) or any other annotation is invalid. The offset fixes the instant.
- `now` is the caller's: GMT does not read the clock here.
- Returns `""` on invalid input, including `cutoffAt`'s `""` sentinel.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `now` | `string` | ISO 8601 instant string of the moment asked about |
| `cutoff` | `string` | ISO 8601 zoned datetime string of the cut-off, exactly as `cutoffAt` returns it |

## Returns

ISO 8601 duration from now to the cut-off, negative after it, or "" on invalid input

## Examples

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

timeToCutoff("2024-06-10T15:00:00Z", "2024-06-12T17:00:00+02:00[Europe/Amsterdam]") // "PT48H"
```

## Source

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