-
Notifications
You must be signed in to change notification settings - Fork 1
/
dateobj.html
55 lines (47 loc) · 1.41 KB
/
dateobj.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
function getDates(start, end) {
let dates = []
let currentDate = start
while (currentDate <= end) {
dates.push(new Date(currentDate))
currentDate.setDate(currentDate.getDate() + 1)
}
return dates;
}
let dates = getDates(new Date("2022-11-11"), new Date("2022-11-21"));
let data = []
// let dates = 8
let assigns = [
{ A: 'Off', B: 'Morning', C: 'Night', D: 'Off' },
{ A: 'Off', B: 'Morning', C: 'Night', D: 'Off' },
{ A: 'Morning', B: 'Off', C: 'Off', D: 'Night' },
{ A: 'Morning', B: 'Off', C: 'Off', D: 'Night' },
{ A: 'Off', B: 'Night', C: 'Morning', D: 'Off' },
{ A: 'Off', B: 'Night', C: 'Morning', D: 'Off' },
{ A: 'Night', B: 'Off', C: 'Off', D: 'Morning' },
{ A: 'Night', B: 'Off', C: 'Off', D: 'Morning' },
]
let count = 8
for (let i = 0; i < (dates.length); i++) {
for (let j = 0; j < 8; j++) {
if (data.length >= dates.length) {
break
}
if (j % count < 8) {
data.push({assign: assigns[j], date : dates[i+j]})
}
}
}
console.log(data)
</script>
</body>
</html>