Skip to content

secondsUntilRetryAfter

secondsUntilRetryAfter(value: string): number | null

Return the whole seconds to wait from a Retry-After header value.

  • Takes the header’s value: Retry-After = HTTP-date / delay-seconds (RFC 9110 section 10.2.3), and delay-seconds = 1*DIGIT.
  • Digits are returned as they are, leading zeros allowed, without reading the clock. A value past the largest safe integer returns null.
  • An HTTP-date is read through parseHttpDate (all three formats) and measured from now, rounded up to a whole second so a wait never falls short.
  • A past HTTP date gives a negative number. Check null first, then wait Math.max(0, n): Math.max(0, null) is 0, so an unchecked garbage value means “retry now”.
  • A :60 leap second returns null, though RFC 9110 section 5.6.7 allows it (its time-of-day comment reads “00:00:00 - 23:59:60 (leap second)”): GMT’s parseHttpDate refuses every second above 59.
  • null is invalid input only: an empty or unparsable string such as "soon", a sign, a space, a fraction, non-ASCII digits, digits past the largest safe integer, a non-string, or an HTTP-date with a :60 second.
  • No timeZone: an HTTP-date is always GMT.
ParameterTypeDescription
valuestringthe header’s value: digits, or an HTTP-date

the seconds to wait, negative for a past date, or null for anything else

import { secondsUntilRetryAfter } from "@northguild/gmt/utc/calculate";
secondsUntilRetryAfter("120") // 120 (delay-seconds)
output 

utc/calculate/secondsUntilRetryAfter.ts

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.