# isValidUtcOffset

Industry: Core

## Signature

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

Return true when `value` is a UTC offset in the form the offset-instant pair stores: ISO 8601 extended `±HH:MM`, optionally `±HH:MM:SS`.

- This is the offset `toOffsetInstant` returns and `fromOffsetInstant` takes, and the one `getTimeZoneOffset` and `getZonedOffset` return.
- **The `utcOffset` pattern is the whole check.** Every string it matches is in range (hour `00`–`23`, minute and second `00`–`59`), so this validator is the pattern test plus the answer false for a non-string.
- `Z` is false: it is a designator meaning "this string is already UTC", and for an event at UTC the pair's offset is `+00:00`.
- Seconds are allowed because some zones did not run on a whole minute: `Africa/Monrovia` was `-00:44:30` until 1972. A fraction of a second is false.
- Basic format (`-0400`) and an hour alone (`-04`) are false.
- `-00:00` is true, and the functions that take an offset read it as `+00:00`.
- A function whose result has no zone in it takes this offset in its time zone position too. A function that returns a zoned string, or formats with `Intl`, takes a time zone identifier only: check that with `isValidTimeZone`, which accepts `+0530` and `-08` and rejects an offset with seconds.
- 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 a UTC offset |

## Returns

boolean indicating validity

## Examples

```ts
import { isValidUtcOffset } from "@northguild/gmt/instant/validate";

isValidUtcOffset("-04:00") // true
```

## Source

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