-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.js
35 lines (30 loc) · 1.15 KB
/
utils.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
function convertHMS(value) {
let hours = Math.floor(value / 3600);
let minutes = Math.floor((value - (hours * 3600)) / 60);
let seconds = value - (hours * 3600) - (minutes * 60);
if (hours < 10)
hours = "0" + hours;
if (minutes < 10)
minutes = "0" + minutes;
if (seconds < 10)
seconds = "0" + seconds;
return (hours == 0) ? `${minutes}:${seconds}` : `${hours}:${minutes}:${seconds}`
}
function calculateSeconds(elapsedSeconds, workMinutes, restMinutes) {
const workSeconds = workMinutes * 60
const restSeconds = restMinutes * 60
const fullCycle = workSeconds + restSeconds
let completedCycles = Math.floor(elapsedSeconds / fullCycle);
let residualSeconds = elapsedSeconds % fullCycle;
let onBreak = false;
let remainingSeconds = 0
if (residualSeconds > workSeconds) {
// We are on a break
onBreak = true
residualSeconds = residualSeconds - workSeconds
remainingSeconds = restSeconds - residualSeconds
} else {
remainingSeconds = workSeconds - residualSeconds
}
return {onBreak, completedCycles, remainingSeconds, residualSeconds};
}