This repository has been archived by the owner on Sep 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.js
175 lines (144 loc) · 6.5 KB
/
date.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
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
169
170
171
172
173
174
175
function colorResult(color) {
if (color > 65) {
document.getElementById("dayCount").style.color = "green";
} else if (color <= 65 && color > 50) {
document.getElementById("dayCount").style.color = "orange";
} else if (color <= 50) {
document.getElementById("dayCount").style.color = "red";
document.getElementById("textFunny").innerHTML =
"Sản phẩm dường như không đạt quy định chất lượng!";
document.getElementById("textFunny").style.color = "red";
} else {
document.getElementById("dayCount").style.color = "red";
document.getElementById("textFunny").innerHTML =
"Lỗi rồi kìa. Xem lại NSX, HSD đã nhập chưa nè";
document.getElementById("textFunny").style.color = "red";
}
}
function calDate() {
let nsx = document.getElementById("nsx").value;
let hsd = document.getElementById("hsd").value;
let result = document.getElementById("result").value;
let date_nsx = new Date(nsx);
let date_hsd = new Date(hsd);
let date_result = new Date(result);
let kqTimeTotal = date_hsd.getTime() - date_nsx.getTime();
let kqDaysTotal = kqTimeTotal / (1000 * 3600 * 24);
let kqTimeNow = date_hsd.getTime() - date_result.getTime();
let kqDaysNow = kqTimeNow / (1000 * 3600 * 24);
let results = parseFloat((kqDaysNow / (kqDaysTotal + 1)) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
}
function calDateNsx() {
let getValueNumber = document.getElementById("nsx-number").value;
let getOptions = document.getElementById("nsx-option");
let getValueOption = getOptions.value;
if (getValueOption === "month") {
let nsx = getValueNumber;
let hsd = document.getElementById("hsd").value;
let result = document.getElementById("result").value;
let date_hsd = new Date(hsd);
let date_result = new Date(result);
let kqDaysTotal = nsx * 30;
let kqTimeNow = date_hsd.getTime() - date_result.getTime();
let kqDaysNow = kqTimeNow / (1000 * 3600 * 24);
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
} else if (getValueOption === "day") {
let nsx = getValueNumber;
let hsd = document.getElementById("hsd").value;
let result = document.getElementById("result").value;
let date_hsd = new Date(hsd);
let date_result = new Date(result);
let kqDaysTotal = nsx;
let kqTimeNow = date_hsd.getTime() - date_result.getTime();
let kqDaysNow = kqTimeNow / (1000 * 3600 * 24);
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
} else if (getValueOption === "week") {
let nsx = getValueNumber;
let hsd = document.getElementById("hsd").value;
let result = document.getElementById("result").value;
let date_hsd = new Date(hsd);
let date_result = new Date(result);
let kqDaysTotal = nsx * 7;
let kqTimeNow = date_hsd.getTime() - date_result.getTime();
let kqDaysNow = kqTimeNow / (1000 * 3600 * 24);
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
} else if (getValueOption === "year") {
let nsx = getValueNumber;
let hsd = document.getElementById("hsd").value;
let result = document.getElementById("result").value;
let date_hsd = new Date(hsd);
let date_result = new Date(result);
let kqDaysTotal = nsx * 365;
let kqTimeNow = date_hsd.getTime() - date_result.getTime();
let kqDaysNow = kqTimeNow / (1000 * 3600 * 24);
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
}
}
function calDateHsd() {
let getValueNumber = document.getElementById("hsd-number").value;
let getOptions = document.getElementById("hsd-option");
let getValueOption = getOptions.value;
if (getValueOption === "month") {
let nsx = document.getElementById("nsx").value;
let hsd = getValueNumber;
let result = document.getElementById("result").value;
let date_nsx = new Date(nsx);
let date_result = new Date(result);
let kqDaysTotal = hsd * 30;
let kqTimeBeforeNow = date_result.getTime() - date_nsx.getTime();
let kqTimeNow = kqTimeBeforeNow / (1000 * 3600 * 24);
let kqDaysNow = kqDaysTotal - kqTimeNow - 1;
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
} else if (getValueOption === "day") {
let nsx = document.getElementById("nsx").value;
let hsd = getValueNumber;
let result = document.getElementById("result").value;
let date_nsx = new Date(nsx);
let date_result = new Date(result);
let kqDaysTotal = hsd;
let kqTimeBeforeNow = date_result.getTime() - date_nsx.getTime();
let kqTimeNow = kqTimeBeforeNow / (1000 * 3600 * 24);
let kqDaysNow = kqDaysTotal - kqTimeNow - 1;
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
} else if (getValueOption === "week") {
let nsx = document.getElementById("nsx").value;
let hsd = getValueNumber;
let result = document.getElementById("result").value;
let date_nsx = new Date(nsx);
let date_result = new Date(result);
let kqDaysTotal = hsd * 7;
let kqTimeBeforeNow = date_result.getTime() - date_nsx.getTime();
let kqTimeNow = kqTimeBeforeNow / (1000 * 3600 * 24);
let kqDaysNow = kqDaysTotal - kqTimeNow - 1;
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
} else if (getValueOption === "year") {
let nsx = document.getElementById("nsx").value;
let hsd = getValueNumber;
let result = document.getElementById("result").value;
let date_nsx = new Date(nsx);
let date_result = new Date(result);
let kqDaysTotal = hsd * 365;
let kqTimeBeforeNow = date_result.getTime() - date_nsx.getTime();
let kqTimeNow = kqTimeBeforeNow / (1000 * 3600 * 24);
let kqDaysNow = kqDaysTotal - kqTimeNow - 1;
let results = parseFloat((kqDaysNow / kqDaysTotal) * 100).toFixed(2);
document.getElementById("dayCount").innerHTML = results + "%";
colorResult(results);
}
}