MCPcopy
hub / github.com/date-fns/date-fns / formatRFC7231

Function formatRFC7231

pkgs/core/src/formatRFC7231/index.ts:43–61  ·  view source on GitHub ↗
(date: DateArg<Date> & {})

Source from the content-addressed store, hash-verified

41 * //=> 'Wed, 18 Sep 2019 19:00:52 GMT'
42 */
43export function formatRFC7231(date: DateArg<Date> & {}): string {
44 const _date = toDate(date);
45
46 if (!isValid(_date)) {
47 throw new RangeError("Invalid time value");
48 }
49
50 const dayName = days[_date.getUTCDay()];
51 const dayOfMonth = addLeadingZeros(_date.getUTCDate(), 2);
52 const monthName = months[_date.getUTCMonth()];
53 const year = _date.getUTCFullYear();
54
55 const hour = addLeadingZeros(_date.getUTCHours(), 2);
56 const minute = addLeadingZeros(_date.getUTCMinutes(), 2);
57 const second = addLeadingZeros(_date.getUTCSeconds(), 2);
58
59 // Result variables.
60 return `${dayName}, ${dayOfMonth} ${monthName} ${year} ${hour}:${minute}:${second} GMT`;
61}

Callers 1

test.tsFile · 0.90

Calls 3

toDateFunction · 0.90
isValidFunction · 0.90
addLeadingZerosFunction · 0.90

Tested by

no test coverage detected