Skip to content

addUtc

addUtc(value: string, units: Partial<Record<keyof DurationLike, number>>, options?: { overflow?: "reject" | "constrain" | undefined; }): string

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.
ParameterTypeDescription
valuestringISO UTC datetime string (e.g. “2024-03-10T12:00:00Z”)
unitsPartial<Record<keyof DurationLike, number>>Partial<Record<DateTimeDurationUnit, number>> object specifying units to add

options

How an out-of-range result is handled

OptionTypeDefaultDescription
overflow?"reject" | "constrain" (Overflow)"constrain", Temporal’s default.What to do when the result is not a real date. "constrain" clamps it to the last valid day, so Jan 31 + 1 month is Feb 29/28 (TC39 Temporal); "reject" returns "".

UTC Instant string after addition, or "" on invalid input

import { addUtc } from "@northguild/gmt/utc/calculate";
addUtc("2024-03-10T12:00:00Z", { days: 5 }) // "2024-03-15T12:00:00Z"
output 

utc/calculate/addUtc.ts