-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculateRestrictDays.html
More file actions
56 lines (48 loc) · 1.67 KB
/
calculateRestrictDays.html
File metadata and controls
56 lines (48 loc) · 1.67 KB
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 lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" name="initDate" id="initDate" value="12/07/2018">
<input type="text" name="endDate" id="endDate" value="31/07/2018">
<button id="btnCalculate">calcular</button>
<div id="output"></div>
<script>
function calculateRestrictDays(initDate, endDate){
//console.log(initDate);
//console.log(endDate);
const arrInitDate = initDate.split('/');
const arrEndDate = endDate.split('/');
const initDay = Number.parseInt(arrInitDate[0], 10);
//console.log("initDay", initDay);
const endDay = Number.parseInt(arrEndDate[0], 10);
//console.log("endDay", endDay);
const month = arrInitDate[1];
//console.log("month", month);
const year = arrInitDate[2];
//console.log("year", year);
const addDays = endDay - initDay;
//console.log("addDays", addDays);
const lengthAddDays = initDay + addDays;
//console.log("lengthAddDays", lengthAddDays);
const dates = [];
for(let i=initDay;i<=lengthAddDays;i++) {
let day = i;
if(day<10) day = `0${i}`;
dates.push(`"${year}-${month}-${day}"`);
}
//console.log(dates);
const output = document.getElementById("output");
output.innerHTML = `[${dates.join(", ")}]`;
}
document.getElementById("btnCalculate")
.addEventListener("click", function(){
calculateRestrictDays(
document.getElementById("initDate").value,
document.getElementById("endDate").value
)}, false);
</script>
</body>
</html>