Skip to content

negateDuration

  • The core functions, which every industry uses.
negateDuration(value: string): string

Flip the sign of an ISO 8601 duration string.

  • Uses Temporal.Duration.from and .negated, then .toString() to re-emit.
  • Negating is a pure sign flip on every component, so it never needs relativeTo — calendar-unit durations round-trip through it fine, unlike addDuration/totalDuration.
  • A zero-length duration has no sign to flip and comes back as “PT0S”, the canonical spelling Temporal emits for every zero duration (so “P0D” also renders “PT0S”).
  • Returns "" when value is not a valid ISO 8601 duration string.
ParameterTypeDescription
valuestringISO 8601 duration string

ISO 8601 duration string with the opposite sign, or "" on invalid input

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

duration/calculate/negateDuration.ts

Accessibility
© 2026 NorthGuild · Licences

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.