secondsUntilHttpDate
Signature
Section titled “Signature”secondsUntilHttpDate(value: string): number | nullReturn the whole seconds from now until an HTTP header date, such as Expires.
- Rounded up to a whole second, so a wait of that length never falls short.
result <= 0means the date has been reached. - A past date gives a negative number, and
nullis invalid input only. Checknullfirst, then waitMath.max(0, n):Math.max(0, null)is 0, so an uncheckednullreads as “no wait”. - An
Expiresreader treatsnullas already expired: RFC 9111 section 5.3 says a cache “MUST interpret invalid date formats, especially the value “0”, as representing a time in the past”. - A
:60leap second returns null, though RFC 9110 section 5.6.7 allows it (itstime-of-daycomment reads “00:00:00 - 23:59:60 (leap second)”): GMT’sparseHttpDaterefuses every second above 59. - Reads all three formats RFC 9110 section 5.6.7 says a recipient must accept, through
parseHttpDate: IMF-fixdate, rfc850 and asctime. AnythingparseHttpDaterefuses returns null, a wrong weekday included. - An rfc850 date reads the clock twice:
parseHttpDateplaces its two-digit year, then this function measures the distance. The distance comes from the later read, so a wait cannot fall short. - No
timeZone: an HTTP-date is always GMT. - For a
Retry-Aftervalue, which may also be digits, usesecondsUntilRetryAfter.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | an HTTP-date, such as Fri, 18 Jun 2027 12:00:00 GMT |
Returns
Section titled “Returns”whole seconds until value, negative when it is past, or null for anything that is not an HTTP-date
Examples
Section titled “Examples”import { secondsUntilHttpDate } from "@northguild/gmt/utc/calculate";
secondsUntilHttpDate("Fri, 18 Jun 2027 12:00:00 GMT") // 259200 (3 days, from a clock at Tue, 15 Jun 2027 12:00:00 GMT)Source
Section titled “Source”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.