mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
timer routes
This commit is contained in:
25
packages/shared/src/utils/time-tracking.ts
Normal file
25
packages/shared/src/utils/time-tracking.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user