# isValidHttpDate

Industry: Core

## Signature

```ts
isValidHttpDate(value: string): boolean
isValidHttpDate(value: void | {} | null | undefined): boolean
isValidHttpDate(value: unknown): value is string
```

Return true when `value` is a real HTTP header date: the RFC 9110 §5.6.7 HTTP-date that headers like `Last-Modified`, `Date` and `Expires` carry, such as `Fri, 15 Mar 2024 14:30:00 GMT`.

- True exactly when `parseHttpDate` returns a UTC string for the same value: the validator calls the parser, so the two cannot disagree.
- **All three HTTP-date formats**, which RFC 9110 §5.6.7 says a recipient "MUST accept": IMF-fixdate, and the obsolete rfc850-date (`Sunday, 06-Nov-94 08:49:37 GMT`) and asctime-date (`Sun Nov  6 08:49:37 1994`). The `httpDate` pattern matches IMF-fixdate alone.
- Checks the calendar as well as the shape. The pattern matches a day that does not exist: `31 Feb`, `29 Feb 2023` and `31 Jun` are false here.
- **The day name must match the date, in all three formats.** The pattern does not check it.
- False for an hour above 23 and a minute above 59, which the pattern matches. False for a second of 60: GMT rejects leap seconds.
- HTTP-date is case-sensitive and fixed-width, and its zone is the literal `GMT`: a numeric offset is false.
- **An rfc850-date reads the clock.** Its two-digit year is read against the current instant (`Temporal.Now.instant()`), as `parseHttpDate` describes, so the same string can change its answer decades apart; if the clock cannot be read the answer is false. The other two formats never read the clock.
- A value that is not a string, a `String` object included, returns `false`. A `true` result narrows an `unknown` value to `string`.
- Read the value with `parseHttpDate`; write one with `formatHttpDate`.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | any value; a string is checked as an RFC 9110 HTTP-date |

## Returns

boolean indicating validity

## Examples

```ts
import { isValidHttpDate } from "@northguild/gmt/utc/validate";

isValidHttpDate("Fri, 15 Mar 2024 14:30:00 GMT") // true
```

## Source

[utc/validate/isValidHttpDate.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/utc/validate/isValidHttpDate.ts)
