-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
util.ts
39 lines (38 loc) 路 909 Bytes
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { sprintf } from "./vendor/https/deno.land/std/fmt/sprintf.ts";
const kDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const kMonths = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
];
export function dateToDateHeader(time: Date = new Date()): string {
//Date: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
//Date: Wed, 21 Oct 2015 07:28:00 GMT
const day = kDays[time.getUTCDay()];
const date = time.getUTCDate();
const month = kMonths[time.getUTCMonth()];
const year = time.getUTCFullYear();
const hour = time.getUTCHours();
const min = time.getUTCMinutes();
const sec = time.getUTCSeconds();
return sprintf(
"%s, %02d %s %d %02d:%02d:%02d GMT",
day,
date,
month,
year,
hour,
min,
sec
);
}