timer routes

This commit is contained in:
Oliver Bryan
2026-01-09 21:54:21 +00:00
parent f04baeb052
commit d6604d2843
9 changed files with 252 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
export function isTimerRunning(timestamps: Date[]): boolean {
return timestamps.length % 2 === 1;
}
export function calculateWorkTimeMs(timestamps: Date[]): number {
let total = 0;
for (let i = 0; i < timestamps.length; i += 2) {
const start = timestamps[i];
if (!start) break;
const end = timestamps[i + 1] || new Date();
total += end.getTime() - start.getTime();
}
return total;
}
export function calculateBreakTimeMs(timestamps: Date[]): number {
let total = 0;
for (let i = 1; i < timestamps.length - 1; i += 2) {
const start = timestamps[i];
const end = timestamps[i + 1];
if (!start || !end) break;
total += end.getTime() - start.getTime();
}
return total;
}