-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (53 loc) · 1.91 KB
/
script.js
File metadata and controls
84 lines (53 loc) · 1.91 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// date
let date = new Date();
let time = date.getTime();
let today = time;
let incrementer = 1000*60*60*24;
const minute = document.getElementById("minutes");
// working out the minutes for the past thirty days
function firstThirtyDays(minutes) {
let sum = 0;
let limiter = minutes.length < 30 ? minutes.length : 30;
return minutes.slice(0, limiter).reduce((acc, el) => acc + el, 0);
}
// Gitpod availability in minutes
const gitpodUsage = array => {
if (new Date(time).getMonth() > new Date(date).getMonth()) {
return 50 * 60;
} else {
return (50 * 60) - firstThirtyDays(array);
}
}
// element for weekday headings
const weekdays = () => {
minute.innerHTML = ``;
for (let i=0; i<7; i++) {
minute.innerHTML += `<span class="days">${new Date (today).toLocaleString("default", { weekday: "long" })}</span>`;
today += incrementer;
}
return minute.innerHTML += `<br /><br />`;
}
weekdays();
// check if the array needs resetting
const resetCheck = array => {
if (array.reduce((acc, el) => acc + el, 0) === 0) {
alert("Please reset the gitpodMinutes array");
minute.innerText = "Please reset the gitpodMinutes array";
} else if (array.reduce((acc, el) => acc + el, 0) > 0) {
let counter = 30;
while (counter > 0) {
minute.innerHTML += `<span>
<article>${new Date (time).getDate()} ${new Date (time).toLocaleString("default", { month: "long" })}</article>
<article>Hours: ${Math.floor(gitpodUsage(array) / 60)}</article>
<article>Minutes: ${Math.floor(((gitpodUsage(array) / 60) - Math.floor(gitpodUsage(array) / 60)) * 60)}</article>
<article>Credits: ${Math.floor(gitpodUsage(array) / 6)}</article>
</span>`;
array.unshift(0);
counter--;
time += incrementer;
}
} else {
alert("Please make sure the gitpodMinutes array only contains positive numbers");
}
}
resetCheck(gitpodMinutes);