MCPcopy Create free account
hub / github.com/nodejs/node / parseAscTimeDate

Function parseAscTimeDate

deps/undici/src/lib/util/date.js:237–434  ·  view source on GitHub ↗

* @see https://httpwg.org/specs/rfc9110.html#obsolete.date.formats * * @param {string} date * @returns {Date | undefined}

(date)

Source from the content-addressed store, hash-verified

235 * @returns {Date | undefined}
236 */
237function parseAscTimeDate (date) {
238 // This is assumed to be in UTC
239
240 if (
241 date.length !== 24 ||
242 date[7] !== ' ' ||
243 date[10] !== ' ' ||
244 date[19] !== ' '
245 ) {
246 return undefined
247 }
248
249 let weekday = -1
250 if (date[0] === 'S' && date[1] === 'u' && date[2] === 'n') { // Sunday
251 weekday = 0
252 } else if (date[0] === 'M' && date[1] === 'o' && date[2] === 'n') { // Monday
253 weekday = 1
254 } else if (date[0] === 'T' && date[1] === 'u' && date[2] === 'e') { // Tuesday
255 weekday = 2
256 } else if (date[0] === 'W' && date[1] === 'e' && date[2] === 'd') { // Wednesday
257 weekday = 3
258 } else if (date[0] === 'T' && date[1] === 'h' && date[2] === 'u') { // Thursday
259 weekday = 4
260 } else if (date[0] === 'F' && date[1] === 'r' && date[2] === 'i') { // Friday
261 weekday = 5
262 } else if (date[0] === 'S' && date[1] === 'a' && date[2] === 't') { // Saturday
263 weekday = 6
264 } else {
265 return undefined // Not a valid day of the week
266 }
267
268 let monthIdx = -1
269 if (
270 (date[4] === 'J' && date[5] === 'a' && date[6] === 'n')
271 ) {
272 monthIdx = 0 // Jan
273 } else if (
274 (date[4] === 'F' && date[5] === 'e' && date[6] === 'b')
275 ) {
276 monthIdx = 1 // Feb
277 } else if (
278 (date[4] === 'M' && date[5] === 'a')
279 ) {
280 if (date[6] === 'r') {
281 monthIdx = 2 // Mar
282 } else if (date[6] === 'y') {
283 monthIdx = 4 // May
284 } else {
285 return undefined // Invalid month
286 }
287 } else if (
288 (date[4] === 'J')
289 ) {
290 if (date[5] === 'a' && date[6] === 'n') {
291 monthIdx = 0 // Jan
292 } else if (date[5] === 'u') {
293 if (date[6] === 'n') {
294 monthIdx = 5 // Jun

Callers 1

parseHttpDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected