Returns number | null
Unix timestamp (ms) if valid, null otherwise
Supported formats (per RFC 6265 §5.1.1 and real-world broken variants):
| Format |
Example |
| HTTP-date (RFC 5322) |
"Thu, 01 Jan 2099 00:00:00 GMT" |
| RFC 850 |
"Thursday, 01-Jan-99 00:00:00 GMT" |
| ANSI C asctime() |
"Thu Jan 1 00:00:00 2099" |
| Short numeric |
"01/01/2099 00:00:00" |
| Cookie spec (RFC 2109) |
"Thu, 01-Jan-2099 00:00:00 GMT" |
| Broken variants (lenient) |
Various real-world malformed dates |
Algorithm:
- Tokenize input into time, month, day-of-month, year tokens
- Extract time component (HH:MM:SS format)
- Extract month (3-letter or full name)
- Extract day-of-month (1-31)
- Extract year (2-digit with RFC 6265 §5.1.1 step 3 mapping, or 4-digit)
- Validate: year must be 1601-9999, day must be 1-31
- Return UTC timestamp or null if invalid
Notes:
- Two-digit years are mapped: 00-69 → 2000-2069, 70-99 → 1970-1999
- Lenient on whitespace and minor format variations
- Returns null for dates with missing components or invalid ranges
Parse a cookie date string per RFC 6265 §5.1.1