parseDuration
Playground
call
result
Signature
Section titled “Signature”parseDuration(value: string, options?: { smallestUnit?: Temporal.ToStringPrecisionOptions; fractionalSecondDigits?: Temporal.ToStringPrecisionOptions; roundingMode?: Temporal.ToStringPrecisionOptions; }): stringimport { parseDuration } from "@northguild/gmt/duration/parse";Parse and re-normalize an ISO 8601 duration string.
- Uses Temporal.Duration.from to parse, then .toString() to re-emit.
smallestUnit,fractionalSecondDigits, androundingModecontrol the precision/rounding of the re-emitted string, per Temporal’s ToStringPrecisionOptions.- Returns “” for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO 8601 duration string |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
smallestUnit? |
Temporal.ToStringPrecisionOptions |
— |
fractionalSecondDigits? |
Temporal.ToStringPrecisionOptions |
— |
roundingMode? |
Temporal.ToStringPrecisionOptions |
— |
Returns
Section titled “Returns”re-normalized ISO 8601 duration string, or “” on invalid input
Examples
Section titled “Examples”parseDuration("P1DT2H30M") // "P1DT2H30M"parseDuration("PT1.5S") // "PT1.5S"parseDuration("PT1.5S", { smallestUnit: "second" }) // "PT1S"parseDuration("PT1.5S", { fractionalSecondDigits: 3 }) // "PT1.500S"parseDuration("invalid") // ""