1 | import { addLeadingZeros } from "./_lib/addLeadingZeros.js";
|
2 | import { isValid } from "./isValid.js";
|
3 | import { toDate } from "./toDate.js";
|
4 |
|
5 | const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
6 |
|
7 | const months = [
|
8 | "Jan",
|
9 | "Feb",
|
10 | "Mar",
|
11 | "Apr",
|
12 | "May",
|
13 | "Jun",
|
14 | "Jul",
|
15 | "Aug",
|
16 | "Sep",
|
17 | "Oct",
|
18 | "Nov",
|
19 | "Dec",
|
20 | ];
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export function formatRFC7231(date) {
|
43 | const _date = toDate(date);
|
44 |
|
45 | if (!isValid(_date)) {
|
46 | throw new RangeError("Invalid time value");
|
47 | }
|
48 |
|
49 | const dayName = days[_date.getUTCDay()];
|
50 | const dayOfMonth = addLeadingZeros(_date.getUTCDate(), 2);
|
51 | const monthName = months[_date.getUTCMonth()];
|
52 | const year = _date.getUTCFullYear();
|
53 |
|
54 | const hour = addLeadingZeros(_date.getUTCHours(), 2);
|
55 | const minute = addLeadingZeros(_date.getUTCMinutes(), 2);
|
56 | const second = addLeadingZeros(_date.getUTCSeconds(), 2);
|
57 |
|
58 |
|
59 | return `${dayName}, ${dayOfMonth} ${monthName} ${year} ${hour}:${minute}:${second} GMT`;
|
60 | }
|
61 |
|
62 |
|
63 | export default formatRFC7231;
|