-
Notifications
You must be signed in to change notification settings - Fork 16
/
H4xx.js
68 lines (44 loc) · 1.47 KB
/
H4xx.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
const off = (new Date ()).getTimezoneOffset (), lag = off * 60000
const TZ_HH_MM =
(off > 0 ? '-' : '+') +
(new Date (2000, 1, 1, 0, -2 * off, 0))
.toJSON () // 2000-02-01T03:00:00.000Z in MSK
.slice (11, 16) // 03:00
Date.prototype.toISOZString = Date.prototype.toISOString
Date.prototype.toISOString = function () {
return (new Date (this.getTime () - lag)) // Greenwich date with time like local one
.toISOZString ().substr (0, 23) // YYYY-MM-DDThh:mm:ss.iii
+ TZ_HH_MM // with our TZ suffix appended
}
}
{
const console_log = console.log
console.log = function () {
let a = [new Date ().toISOString ()]
for (let i of arguments)
if (a.length == 1 && typeof i == 'string' && i.indexOf ('%s') > -1)
a [0] += ' ' + i; else a.push (i)
console_log.apply (console, a)
}
}
global.clone = (o) => {
if (typeof o != 'object') return o
return JSON.parse (JSON.stringify (o))
}
global.darn = (o) => {
console.log (o)
return (o)
}
global.suicide = (x) => {
darn ('[ERROR] ' + x)
process.exit (1)
}
global.not_off = (i) => !i.off
global.dt_iso = (dt) => {
let ymd = dt.substr (0, 10).split (/\D/)
if (ymd [0].length == 2) ymd.reverse ()
return ymd.join ('-')
}
global.is_uuid = s => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test (s)
global.ZERO_UUID = '00000000-0000-0000-0000-000000000000'