Skip to content

addUtc

addUtc(value: string, units: Partial<Record<DateTimeDurationUnit, number>>, options?: { overflow?: Overflow; }): string
import { addUtc } from "@northguild/gmt/utc/calculate";

Add a temporal amount to a UTC datetime string and return a new UTC Instant string.

  • Uses Temporal.Instant.from to parse, adds duration, returns new Instant.
  • Validates duration units and values.
  • Returns “” for invalid input. overflow (“constrain” (default) | “reject”) controls out-of-range results, e.g. adding 1 month to Jan 31: “constrain” clamps to Feb 29/28, “reject” throws (resulting in “”).
Parameter Type Description
value string ISO UTC datetime string (e.g. “2024-03-10T12:00:00Z”)
units Partial&lt;Record&lt;DateTimeDurationUnit, number&gt;&gt; Partial<Record<DateTimeDurationUnit, number>> object specifying units to add

options

Option Type Default
overflow? Overflow

UTC Instant string after addition, or “” on invalid input

addUtc("2024-03-10T12:00:00Z", { days: 5 }) // "2024-03-15T12:00:00Z"
addUtc("2024-03-10T12:00:00Z", { months: 1, years: 1 }) // "2025-04-10T12:00:00Z"
addUtc("invalid", { days: 5 }) // ""

utc/calculate/addUtc.ts