-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
53 lines (39 loc) · 1.43 KB
/
main.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
import * as helper from "./helper.mjs";
const totalBlockDurationMinutes = parseInt(
document.getElementById("total-block-duration").value,
);
const sessionDurationMinutes = parseInt(
document.getElementById("session-duration").value,
);
const shortBreakDuration = parseInt(
document.getElementById("short-break-duration").value,
);
const longBreakDuration = parseInt(
document.getElementById("long-break-duration").value,
);
const sessionsPerCycle = parseInt(
document.getElementById("sessions-per-cycle").value,
);
const startTime = document.getElementById("start-time").value;
const calculateButton = document.getElementById("calculate-button");
calculateButton.addEventListener("click", () => {
calculate();
});
function calculate() {
const endTime = helper.calculateEndTime(startTime, totalBlockDurationMinutes);
const cycleDurationMinutes =
(sessionDurationMinutes + shortBreakDuration) * sessionsPerCycle -
shortBreakDuration +
longBreakDuration;
const cycleCoefficient = totalBlockDurationMinutes / cycleDurationMinutes;
const focusTimePerCycle = sessionDurationMinutes * sessionsPerCycle;
const breakTimePerCycle = cycleDurationMinutes - focusTimePerCycle;
const totalFocusTime = helper.floorToMultipleOf(
focusTimePerCycle * cycleCoefficient,
sessionDurationMinutes,
);
const totalBreakTime = helper.floorToMultipleOf(
breakTimePerCycle * cycleCoefficient,
shortBreakDuration,
);
}