UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

21 lines (20 loc) 928 B
/** * 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. * * @param value ISO 8601 duration string * @returns ISO 8601 duration string with a positive sign, or "" on invalid input * * @example absDuration("-P1DT2H") // "P1DT2H" * @example absDuration("P1DT2H") // "P1DT2H" * @example absDuration("-P1Y2M") // "P1Y2M" (no relativeTo needed) * @example absDuration("PT0S") // "PT0S" * @example absDuration("not a duration") // "" */ export declare function absDuration(value: string): string;