-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshifts.js
More file actions
66 lines (65 loc) · 1.75 KB
/
Copy pathshifts.js
File metadata and controls
66 lines (65 loc) · 1.75 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
57
58
59
60
61
62
63
64
65
66
class Shifts {
static getRefDate() {
return 1581634800000;
}
static getDayDifference(dateArray) {
const day = 86400000,
dayDifference =
(new Date(...dateArray).valueOf() - this.getRefDate()) / day;
return {
days: Math.round(Math.abs(dayDifference)),
positive: dayDifference >= 0
};
}
static getShiftNumber(dateArray, night) {
const { days, positive } = this.getDayDifference(dateArray),
dayPattern = [3, 2, 1, 4, 3],
nightPattern = [4, 3, 2, 1, 4],
counter = positive ? days % 4 : 4 - (days % 4);
if (!night) {
return dayPattern[counter];
} else {
return nightPattern[counter];
}
}
}
function shiftWrap(number) {
switch (number) {
case 1:
return "1 - J.";
case 2:
return "2 - Ad.";
case 3:
return "3 - Al.";
case 4:
return "4 - Ad.";
default:
break;
}
}
function dateStringToArray(dateString) {
const date = new Date(dateString);
return [date.getFullYear(), date.getMonth(), date.getDate()];
}
function getDateInput() {
const date = new Date(document.getElementById("date-picker").value);
return dateStringToArray(date);
}
function checkIfNightChecked() {
return document.getElementById("night").checked;
}
function setOutput(output) {
document.getElementById("output").innerHTML =
typeof output === "number" ? "Zmiana nr " + shiftWrap(output) : "";
console.log(output);
}
function onClick() {
const date = getDateInput(),
night = checkIfNightChecked(),
shift = Shifts.getShiftNumber(date, night);
setOutput(shift);
document.getElementById("output").style.visibility = "visible";
}
function blur(id) {
document.getElementById(id).blur();
}