diff --git a/src/tracker.ts b/src/tracker.ts index 48476a1..9daf635 100644 --- a/src/tracker.ts +++ b/src/tracker.ts @@ -100,6 +100,9 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getFile: let totalDiv = timer.createEl("div", { cls: "simple-time-tracker-timer" }); let total = totalDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" }); totalDiv.createEl("span", { text: "Total" }); + let totalTodayDiv = timer.createEl("div", { cls: "simple-time-tracker-timer" }) + let totalToday = totalTodayDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" }) + totalTodayDiv.createEl("span", { text: "Total Today" }) if (tracker.entries.length > 0) { // add table @@ -145,6 +148,26 @@ export function getDuration(entry: Entry): number { } } +export function getDurationToday(entry: Entry): number { + if (entry.subEntries) { + return getTotalDurationToday(entry.subEntries) + } else { + let today = moment().startOf('day') + let endTime = entry.endTime ? moment(entry.endTime) : moment() + let startTime = moment(entry.startTime) + + if (endTime.isBefore(today)) { + return 0 + } + + if (startTime.isBefore(today)) { + startTime = today + } + + return endTime.diff(startTime) + } +} + export function getTotalDuration(entries: Entry[]): number { let ret = 0; for (let entry of entries) @@ -152,6 +175,13 @@ export function getTotalDuration(entries: Entry[]): number { return ret; } +export function getTotalDurationToday(entries: Entry[]): number { + let ret = 0 + for (let entry of entries) + ret += getDurationToday(entry) + return ret +} + export function isRunning(tracker: Tracker): boolean { return !!getRunningEntry(tracker.entries); }