Skip to content

Commit 82abc91

Browse files
Timer Day Split
- Needs to be tested to confirm but basically when user starts the timer in one day and manages to go into the next day it will now log as two different logs. - One log for the previous day and one for the current with whatever hours are in what day
1 parent 71d4e2b commit 82abc91

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

src/timer.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ async function stopTimer(){
4848
logStopTime = Date.now();
4949
timerActive = false;
5050
const logTime = logStopTime - logStartTime;
51-
const formatLogTime = formatTime(logTime);
51+
console.log(logTime);
52+
53+
await splitAndLogTime(logStartTime, logStopTime);
54+
5255
clearInterval(timerInterval);
53-
await logTimeHandler(formatLogTime);
5456
await populateQuickTimes();
5557
await getAllActiveProjects();
5658
await populateTopicView();
@@ -62,6 +64,28 @@ async function stopTimer(){
6264
api.toggleClockActive();
6365
}
6466

67+
async function splitAndLogTime(startTime, stopTime) {
68+
if (stopTime - startTime < 24 * 60 * 60 * 1000) {
69+
const logDuration = stopTime - startTime;
70+
const formatLogTime = formatTime(logDuration);
71+
await logTimeHandler(formatLogTime);
72+
return;
73+
}
74+
75+
const startOfDay = new Date(startTime);
76+
startOfDay.setHours(0, 0, 0, 0);
77+
const endOfDay = new Date(startOfDay);
78+
endOfDay.setHours(23, 59, 59, 999);
79+
80+
const durationUntilEndOfDay = endOfDay.getTime() - startTime;
81+
82+
const formatLogTime = formatTime(durationUntilEndOfDay);
83+
await logTimeHandler(formatLogTime);
84+
85+
const nextDayStartTime = endOfDay.getTime() + 1;
86+
await splitAndLogTime(nextDayStartTime, stopTime);
87+
}
88+
6589
function updateTimer(){
6690
const currentTime = Date.now() - logStartTime;
6791
timerText_el.textContent = formatTime(currentTime);

0 commit comments

Comments
 (0)