* @see https://httpwg.org/specs/rfc9110.html#obsolete.date.formats * * @param {string} date * @returns {Date | undefined}
(date)
| 440 | * @returns {Date | undefined} |
| 441 | */ |
| 442 | function parseRfc850Date (date) { |
| 443 | let commaIndex = -1 |
| 444 | |
| 445 | let weekday = -1 |
| 446 | if (date[0] === 'S') { |
| 447 | if (date[1] === 'u' && date[2] === 'n' && date[3] === 'd' && date[4] === 'a' && date[5] === 'y') { |
| 448 | weekday = 0 // Sunday |
| 449 | commaIndex = 6 |
| 450 | } else if (date[1] === 'a' && date[2] === 't' && date[3] === 'u' && date[4] === 'r' && date[5] === 'd' && date[6] === 'a' && date[7] === 'y') { |
| 451 | weekday = 6 // Saturday |
| 452 | commaIndex = 8 |
| 453 | } |
| 454 | } else if (date[0] === 'M' && date[1] === 'o' && date[2] === 'n' && date[3] === 'd' && date[4] === 'a' && date[5] === 'y') { |
| 455 | weekday = 1 // Monday |
| 456 | commaIndex = 6 |
| 457 | } else if (date[0] === 'T') { |
| 458 | if (date[1] === 'u' && date[2] === 'e' && date[3] === 's' && date[4] === 'd' && date[5] === 'a' && date[6] === 'y') { |
| 459 | weekday = 2 // Tuesday |
| 460 | commaIndex = 7 |
| 461 | } else if (date[1] === 'h' && date[2] === 'u' && date[3] === 'r' && date[4] === 's' && date[5] === 'd' && date[6] === 'a' && date[7] === 'y') { |
| 462 | weekday = 4 // Thursday |
| 463 | commaIndex = 8 |
| 464 | } |
| 465 | } else if (date[0] === 'W' && date[1] === 'e' && date[2] === 'd' && date[3] === 'n' && date[4] === 'e' && date[5] === 's' && date[6] === 'd' && date[7] === 'a' && date[8] === 'y') { |
| 466 | weekday = 3 // Wednesday |
| 467 | commaIndex = 9 |
| 468 | } else if (date[0] === 'F' && date[1] === 'r' && date[2] === 'i' && date[3] === 'd' && date[4] === 'a' && date[5] === 'y') { |
| 469 | weekday = 5 // Friday |
| 470 | commaIndex = 6 |
| 471 | } else { |
| 472 | // Not a valid day name |
| 473 | return undefined |
| 474 | } |
| 475 | |
| 476 | if ( |
| 477 | date[commaIndex] !== ',' || |
| 478 | (date.length - commaIndex - 1) !== 23 || |
| 479 | date[commaIndex + 1] !== ' ' || |
| 480 | date[commaIndex + 4] !== '-' || |
| 481 | date[commaIndex + 8] !== '-' || |
| 482 | date[commaIndex + 11] !== ' ' || |
| 483 | date[commaIndex + 14] !== ':' || |
| 484 | date[commaIndex + 17] !== ':' || |
| 485 | date[commaIndex + 20] !== ' ' || |
| 486 | date[commaIndex + 21] !== 'G' || |
| 487 | date[commaIndex + 22] !== 'M' || |
| 488 | date[commaIndex + 23] !== 'T' |
| 489 | ) { |
| 490 | return undefined |
| 491 | } |
| 492 | |
| 493 | let day = 0 |
| 494 | if (date[commaIndex + 2] === '0') { |
| 495 | // Single digit day, e.g. "Sun Nov 6 08:49:37 1994" |
| 496 | const code = date.charCodeAt(commaIndex + 3) |
| 497 | if (code < 49 || code > 57) { |
| 498 | return undefined // Not a digit |
| 499 | } |