(date: DateArg<Date> & {})
| 41 | * //=> 'Wed, 18 Sep 2019 19:00:52 GMT' |
| 42 | */ |
| 43 | export 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 | } |
no test coverage detected