@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
28 lines • 1.37 kB
TypeScript
import { DateTimeDurationUnit } from "../../types/date-time-duration-units.js";
import { Overflow } from "../../types/overflow.js";
import "../../types/index.js";
/**
* Subtract a temporal amount from a UTC datetime string and return a new UTC Instant string.
*
* - Uses Temporal.Instant.from to parse, subtracts duration, returns new Instant.
* - Validates duration units and values.
* - Returns "" for invalid input.
*
* @param value ISO UTC datetime string (e.g. "2024-03-10T12:00:00Z")
* @param units Partial<Record<DateTimeDurationUnit, number>> object specifying units to subtract
* @param options How an out-of-range result is handled
* @returns UTC Instant string after subtraction, or "" on invalid input
*
* @example subtractUtc("2024-03-15T12:00:00Z", { days: 5 }) // "2024-03-10T12:00:00Z"
* @example subtractUtc("2024-03-15T12:00:00Z", { months: 1, years: 1 }) // "2023-02-15T12:00:00Z"
* @example subtractUtc("invalid", { days: 5 }) // ""
*/
export declare function subtractUtc(value: string, units: Partial<Record<DateTimeDurationUnit, number>>, options?: {
/**
* What to do when the result is not a real date. `"constrain"` clamps it to the last valid day,
* so Mar 31 − 1 month is Feb 29/28 (TC39 Temporal); `"reject"` returns `""`.
*
* @defaultValue `"constrain"`, Temporal's default.
*/
overflow?: Overflow;
}): string;