-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.html
56 lines (48 loc) · 1.61 KB
/
date.html
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
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0px;
padding: 10px;
}
textarea {
width: 100%;
min-width: 100%;
max-width: 100%;
box-sizing: border-box;
}
* {
font-family: monospace;
}
</style>
</head>
<body>
<textarea></textarea>
<div></div>
<script>
function dateCalcSum(times) {
times = times instanceof Array ? times : times.replace(
/ |\t|^\n|\n$/g, ""
).split("\n");
var result = 0;
times.forEach(function (time) {
time = time instanceof Array ? time : time.split("-");
var startTime = eval(time[1].split(":").map(
(v, i) => (i ? v : v * 60) | 0
).join("+"));
var endTime = eval(time[0].split(":").map(
(v, i) => (i ? v : v * 60) | 0
).join("+"));
result += endTime - startTime;
});
return result;
}
document.querySelector("textarea").oninput = function () {
document.querySelector("div").innerHTML = `time remains: ${
Math.ceil((20 - (dateCalcSum(this.value) / 60)) * 100) / 100
}hr`;
}
</script>
</body>
</html>