Skip to content

absDuration

absDuration(value: string): string

Return the absolute value of an ISO 8601 duration string.

  • Uses Temporal.Duration.from and .abs, then .toString() to re-emit.
  • Like negateDuration, this only touches signs, so it never needs relativeTo and works on calendar-unit durations.
  • An already-positive duration is returned re-emitted, not rejected — but re-emitted means canonicalized, so “P0D” comes back as “PT0S”.
  • Returns "" when value is not a valid ISO 8601 duration string.
ParameterTypeDescription
valuestringISO 8601 duration string

ISO 8601 duration string with a positive sign, or "" on invalid input

import { absDuration } from "@northguild/gmt/duration/calculate";
absDuration("-P1DT2H") // "P1DT2H"
output 

duration/calculate/absDuration.ts