# getZonedOffsetAs

Industry: Core

## Signature

```ts
getZonedOffsetAs(value: string, unit: ZonedOffsetUnit): number | null
```

Read a zoned value's UTC offset as a number, in the given unit.

- Subsumes what would otherwise be `getZonedOffsetMinutes` / `getZonedOffsetNanoseconds` — one differently-scaled reading of the same underlying quantity through a single parameterized call, following J8's `getDurationUnit(value, unit)` precedent (Decision 5).
- "nanoseconds" reads Temporal's `offsetNanoseconds` directly.
- "minutes" divides by 60e9 — every IANA offset is a whole number of minutes, so this never truncates a fraction.
- Negative offsets (west of UTC) return a negative number.
- `unit` accepts the plural or singular name (`"minutes"` or `"minute"`), as Temporal does.
- Returns null on invalid `value` or `unit`.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | zoned ISO 8601 datetime string |
| `unit` | `ZonedOffsetUnit` | "minutes" \| "nanoseconds" (or the singular "minute" \| "nanosecond") |

## Returns

the offset in the requested unit, or null on invalid input

## Types

### ZonedOffsetUnit

Unit a zoned value's UTC offset can be read as via `getZonedOffsetAs`.

```ts
import type { ZonedOffsetUnit } from "@northguild/gmt";
```

```ts
"minutes" | "nanoseconds" | "minute" | "nanosecond"
```

## Examples

```ts
import { getZonedOffsetAs } from "@northguild/gmt/zoned/parse";

getZonedOffsetAs("2024-07-15T12:00:00-03:00[America/Sao_Paulo]", "minutes") // -180
```

## Source

[zoned/parse/getZonedOffsetAs.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/zoned/parse/getZonedOffsetAs.ts)
