# isValidInstant

Industry: Core

## Signature

```ts
isValidInstant(value: string): boolean
isValidInstant(value: void | {} | null | undefined): boolean
isValidInstant(value: unknown): value is string
```

Validate whether a string is an ISO 8601 instant string the `precision/` namespace accepts.

- The predicate `toNanoseconds` was missing. `toNanoseconds` returns `0n` for both the epoch and a rejected string, and the only public validator close enough to reach for — `isValidUtc` — is *narrower* than this grammar: it gates on GMT's stricter `<date>T<time>Z` shape and rejects the offsets `toNanoseconds` parses. Validating with it discards valid input. This accepts exactly what `toNanoseconds` does, so the two never disagree.
- Requires an offset designator (`Z`, `±HH:MM[:SS[.fraction]]`) and nothing after it: an annotation of any kind (a time zone, a calendar, an elective one) returns `false`. The offset alone fixes the instant, and an offset written with seconds is read exactly, so `-00:44:30` and `-00:45` are different instants.
- ISO 8601 extended format over the whole string: `<date>T<time>`, then `Z` or `±HH:MM[:SS[.fraction]]`. Basic format, a space or lower-case `t` separator, a lower-case `z` and an hour-only time or offset return `false`, although `Temporal.Instant.from` reads them.
- Rejects leap seconds in every separator and format variant.
- An empty string returns `false`.
- A value that is not a string, a `String` object included, returns `false`. A `true` result narrows an `unknown` value to `string`.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | any value; a string is checked as an ISO 8601 instant string |

## Returns

boolean indicating whether `toNanoseconds` will parse it

## Examples

```ts
import { isValidInstant } from "@northguild/gmt/precision/validate";

isValidInstant("2024-03-10T12:00:00Z") // true
```

## Source

[precision/validate/isValidInstant.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/precision/validate/isValidInstant.ts)
