forked from xmppjs/xmpp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (37 loc) · 920 Bytes
/
index.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
"use strict";
function date(d = new Date()) {
if (typeof d === "string") {
d = new Date(d);
}
return datetime(d).split("T")[0];
}
function time(d = new Date()) {
if (typeof d === "string") {
d = new Date(d);
}
return datetime(d).split("T")[1];
}
function datetime(d = new Date()) {
if (typeof d === "string") {
d = new Date(d);
}
return new Date(d).toISOString().split(".")[0] + "Z";
}
function pad(value) {
return value < 10 ? "0" + value : value;
}
function formatOffset(n) {
const sign = n > 0 ? "-" : "+";
const offset = Math.abs(n);
return sign + pad(Math.floor(offset / 60)) + ":" + pad(offset % 60);
}
function offset(d = new Date()) {
if (typeof d === "string") {
d = new Date(d);
}
return formatOffset(d.getTimezoneOffset());
}
module.exports.date = date;
module.exports.time = time;
module.exports.datetime = datetime;
module.exports.offset = offset;