This commit is contained in:
hen 2024-11-14 19:44:25 -03:00 committed by GitHub
commit ff48e05403
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}