-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
168 lines (145 loc) · 5.89 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
<title>简易产假计算器</title>
</head>
<body>
<div class="container" style="max-width:500px;margin:50px auto;">
<h1>产假计算</h1>
<hr />
<div class="input-group mb-3">
<span class="input-group-text">开始日期:</span>
<input type="date" class="form-control" id="start">
</div>
<div class="input-group mb-3">
<span class="input-group-text">寒假开始日期:</span>
<input type="date" class="form-control" id="whs">
</div>
<div class="input-group mb-3">
<span class="input-group-text">寒假结束日期:</span>
<input type="date" class="form-control" id="whe">
</div>
<div class="input-group mb-3">
<span class="input-group-text">暑假开始日期:</span>
<input type="date" class="form-control" id="shs">
</div>
<div class="input-group mb-3">
<span class="input-group-text">暑假结束日期:</span>
<input type="date" class="form-control" id="she">
</div>
<div class="input-group mb-3">
<span class="input-group-text">次年寒假开始日期:</span>
<input type="date" class="form-control" id="whs2">
</div>
<div class="input-group mb-3">
<span class="input-group-text">次年寒假结束日期:</span>
<input type="date" class="form-control" id="whe2">
</div>
<div class="input-group mb-3">
<select class="form-select" id='length'>
<option value=128>顺产(128天)</option>
<option value=143>剖宫产(143天)</option>
</select>
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" id="bonus">
<span class="ms-2">双胞胎(+15天)</span>
</div>
</div>
<button class="btn btn-primary" onclick="solve();">计算</button>
<p id="out" class="mt-2" style="font-size:20px;"></p>
<hr />
<p class="text-secondary"><i>by Zzzyt, XiaoGeNintendo from Hell Hole Studios. <a
href="https://www.github.com/hellholestudios/vacation-calculator">Github</a></i></p>
</div>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8"
crossorigin="anonymous"></script>
<script>
//TODO save it
function during(a, b, c) {
var B = new Date(b);
var C = new Date(c);
return a >= B && a <= C;
}
function dateToString(date) {
return date.getFullYear() + "-" + ((date.getMonth() + 1) + "").padStart(2, "0") + "-" + (date.getDate() + "").padStart(2, "0");
}
var now = new Date();
var year = now.getFullYear();
function solve() {
if ($("#start").val() === "") {
$("#out").text("请输入开始日期");
return;
}
if ($("#whs").val() === "") {
$("#out").text("请输入寒假开始日期");
return;
}
if ($("#whe").val() === "") {
$("#out").text("请输入寒假结束日期");
return;
}
if ($("#shs").val() === "") {
$("#out").text("请输入寒假开始日期");
return;
}
if ($("#she").val() === "") {
$("#out").text("请输入寒假结束日期");
return;
}
if ($("#whs2").val() === "") {
var tmp = new Date($("#whs").val());
tmp.setFullYear(tmp.getFullYear() + 1);
$("#whs2").val(dateToString(tmp));
}
if ($("#whe2").val() === "") {
var tmp = new Date($("#whe").val());
tmp.setFullYear(tmp.getFullYear() + 1);
$("#whe2").val(dateToString(tmp));
}
var day = parseInt($("#length").val()) + $("#bonus")[0].checked * 15;
var st = new Date($("#start").val());
for (var i = 0; i < day - 1; i++) {
while (during(st, $("#whs").val(), $("#whe").val()) || during(st, $("#shs").val(), $("#she").val()) || during(st, $("#whs2").val(), $("#whe2").val())) {
st.setDate(st.getDate() + 1);
}
st.setDate(st.getDate() + 1);
}
$("#out").text("是" + st.toLocaleDateString() + "!!");
}
function init(year) {
$("#whs").attr('min', year + "-01-01");
$("#whs").attr('max', year + "-12-31");
$("#whs").val("");
$("#whe").attr('min', year + "-01-01");
$("#whe").attr('max', year + "-12-31");
$("#whe").val("");
$("#shs").attr('min', year + "-01-01");
$("#shs").attr('max', year + "-12-31");
$("#shs").val(year + "-07-01");
$("#she").attr('min', year + "-01-01");
$("#she").attr('max', year + "-12-31");
$("#she").val(year + "-08-31");
$("#whs2").attr('min', (year + 1) + "-01-01");
$("#whs2").attr('max', (year + 1) + "-12-31");
$("#whs2").val("");
$("#whe2").attr('min', (year + 1) + "-01-01");
$("#whe2").attr('max', (year + 1) + "-12-31");
$("#whe2").val("");
}
$("#start").val(dateToString(now));
init(year);
$("#start").on("change", () => {
var st = new Date($("#start").val());
if (year !== st.getFullYear()) {
year = st.getFullYear();
init(year);
}
});
</script>
</body>
</html>