UNPKG

844 BJavaScriptView Raw
1'use strict'
2
3const days = 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(',')
4const months = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(',')
5const pad = n => n.toString().padStart(2, '0')
6const parser = /\w\w\w, (\d\d) (\w\w\w) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT/
7
8module.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}