-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.js
57 lines (49 loc) · 1.26 KB
/
lib.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
// Dutch months. Sorry.
monthNames = ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"];
function GET(uri) {
var req = new XMLHttpRequest();
req.open("GET", uri, false);
req.send(null);
return req.responseText;
}
function $(id) {
return document.getElementById(id);
}
function newDiv(appendObj) {
var mydiv = document.createElement("div");
appendObj.appendChild(mydiv);
return mydiv;
}
function obj2style(obj) {
stylestr = '';
for (prop in obj) {
stylestr += prop + ":" + obj[prop] + ";";
}
return stylestr;
}
function datestr2unix(datestr) {
datestr = datestr.split(' ');
if (datestr.length != 3 || datestr[2].split(":").length != 3) {
return false;
}
var date = parseInt(datestr[0]);
var month = monthNames.indexOf(datestr[1]);
var hour = datestr[2].split(":")[0];
var minute = datestr[2].split(":")[1];
var second = datestr[2].split(":")[2];
return (+new Date(2015, month, date, hour, minute, second)) / 1000;
}
function unix2datestr(unix) {
var d = new Date(unix * 1000);
return d.getDate() + " "
+ monthNames[d.getMonth()] + " "
+ leadingZero(d.getHours()) + ":"
+ leadingZero(d.getMinutes()) + ":"
+ leadingZero(d.getSeconds());
}
function leadingZero(n) {
if (n < 10) {
return "0" + n;
}
return "" + n;
}