subtractDuration
Signature
Section titled “Signature”subtractDuration(a: string, b: string): stringCombine two ISO 8601 duration strings by subtraction.
- Uses Temporal.Duration.from and .subtract to combine, then .toString() to re-emit.
- Temporal.Duration.prototype.subtract has no
relativeTooption, so combining any pair where either operand has a nonzero years/months/weeks component throws and results in "" — calendar-unit duration arithmetic needs a reference point that this function does not accept. - The result may be negative (e.g. subtracting a larger duration from a smaller one).
- Returns "" if either operand is not a valid ISO 8601 duration string.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
a | string | ISO 8601 duration string |
b | string | ISO 8601 duration string |
Returns
Section titled “Returns”ISO 8601 duration string representing a - b, or "" on invalid input
Examples
Section titled “Examples”import { subtractDuration } from "@northguild/gmt/duration/calculate";
subtractDuration("P1D", "PT2H") // "PT22H"