forked from SimonWaldherr/parseTime.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
52 lines (48 loc) · 1.56 KB
/
script.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
/*jslint browser: true, indent: 2 */
/*global parseTime */
var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
window.onload = function () {
"use strict";
var i,
retvalue,
ldate,
ltime,
lday,
eles = document.getElementsByTagName('p');
for (i = 0; i < eles.length; i += 1) {
retvalue = parseTime(eles[i].textContent);
if ((retvalue !== undefined) && (retvalue.absolute !== false)) {
ldate = new Date(retvalue.absolute).toLocaleDateString();
ltime = new Date(retvalue.absolute).toLocaleTimeString();
lday = weekdays[new Date(retvalue.absolute).getDay()];
eles[i].innerHTML += '<br/> ' + JSON.stringify(retvalue, null, ' ');
eles[i].innerHTML += '<br/> ' + lday + ' ' + ldate + ' ' + ltime;
} else {
eles[i].style.color = 'red';
eles[i].innerHTML += '<br/> not parsable';
}
}
demo();
};
function demo() {
"use strict";
var ret = '',
ldate,
ltime,
lday,
ele = document.getElementById('ret'),
inp = document.getElementById('inp').value,
retvalue = parseTime(inp);
if ((retvalue !== undefined) && (retvalue.absolute !== false)) {
ldate = new Date(retvalue.absolute).toLocaleDateString();
ltime = new Date(retvalue.absolute).toLocaleTimeString();
lday = weekdays[new Date(retvalue.absolute).getDay()];
ret += JSON.stringify(retvalue);
ret += '<br/> ' + lday + ' ' + ldate + ' ' + ltime;
ele.style.color = 'black';
} else {
ret += 'not parsable';
ele.style.color = 'red';
}
ele.innerHTML = ret;
}