-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.js
More file actions
30 lines (28 loc) · 807 Bytes
/
Copy pathhistory.js
File metadata and controls
30 lines (28 loc) · 807 Bytes
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
function calcStartOfDay(date, spillOverHours) {
const d = new Date(date - (spillOverHours * 60 * 60 * 1000))
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), spillOverHours)
}
function calcHistoryStats(history) {
const stats = {
focusMillis: 0,
pauseMillis: 0,
lastStopTimestamp: 0,
};
if (!history) {
return stats;
}
for (let i = 0; i < history.length; i++) {
const entry = history[i];
stats.focusMillis += entry.stopTimestamp - entry.startTimestamp;
stats.lastStopTimestamp = Math.max(stats.lastStopTimestamp, entry.stopTimestamp);
if (i > 0) {
const prevEntry = history[i - 1];
stats.pauseMillis += entry.startTimestamp - prevEntry.stopTimestamp;
}
}
return stats;
}
export default {
calcStartOfDay,
calcHistoryStats,
};