-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (38 loc) · 1.73 KB
/
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
function validate() {
var data = document.getElementById('applications').value;
var rows = data.split('\n');
for (var row of rows) {
var fields = row.split(' ');
var person = {
name : fields[0],
birth : new Date(fields[1]),
studyStart : new Date(fields[2]),
studyEnd : new Date(fields[3]),
jobStart : new Date(fields[4]),
jobEnd : new Date(fields[5]),
valid : false
}
var studyLengthInYears = millisToYear(person.studyEnd - person.studyStart);
var jobLengthInYears = millisToYear(person.jobEnd - person.jobStart);
if (studyLengthInYears > 5) {
person.valid = true;
}
else if (person.studyStart < new Date('2010-01-01') && studyLengthInYears > 3 && jobLengthInYears > 3) {
person.valid = true;
}
//console.log(person.name + ": " + (person.valid ? "Godkjent" : "Ikke godkjent"));
var tr = document.createElement("tr");
tr.innerHTML += "<td>" + person.name + "</td>";
tr.innerHTML += "<td>" + person.birth.toLocaleDateString() + "</td>";
tr.innerHTML += "<td>" + person.studyStart.toLocaleDateString() + "</td>";
tr.innerHTML += "<td>" + person.studyEnd.toLocaleDateString() + "</td>";
tr.innerHTML += "<td>" + person.jobStart.toLocaleDateString() + "</td>";
tr.innerHTML += "<td>" + person.jobEnd.toLocaleDateString() + "</td>";
tr.classList.add(person.valid ? "table-success" : "table-danger");
document.getElementById('table-rows').appendChild(tr);
}
}
function millisToYear(millis) {
return millis / (1000 * 60 * 60 * 24 * 30 * 12);
}
// validate();