1 | 'use strict'
|
2 |
|
3 | const days = 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(',')
|
4 | const months = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(',')
|
5 | const pad = n => n.toString().padStart(2, '0')
|
6 | const parser = /\w\w\w, (\d\d) (\w\w\w) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT/
|
7 |
|
8 | module.exports = {
|
9 | format (d) {
|
10 | return [
|
11 | days[d.getUTCDay()],
|
12 | ', ',
|
13 | pad(d.getUTCDate()),
|
14 | ' ',
|
15 | months[d.getUTCMonth()],
|
16 | ' ',
|
17 | d.getUTCFullYear(),
|
18 | ' ',
|
19 | pad(d.getUTCHours()),
|
20 | ':',
|
21 | pad(d.getUTCMinutes()),
|
22 | ':',
|
23 | pad(d.getUTCSeconds()),
|
24 | ' GMT'
|
25 | ].join('')
|
26 | },
|
27 |
|
28 | parse (t) {
|
29 | const [, date, monthName, fullYear, hours, minutes, seconds] = t.match(parser)
|
30 | const month = months.indexOf(monthName)
|
31 | return new Date(Date.UTC(fullYear, month, date, hours, minutes, seconds, 0))
|
32 | }
|
33 | }
|