Compare commits

...

3 commits

Author SHA1 Message Date
hen
ff48e05403
Merge 8aa3143793 into 3dc0857ef1 2024-11-14 19:44:25 -03:00
hen
8aa3143793 not change format semicolons 2024-11-14 19:44:04 -03:00
hen
d4188127b3 add total today 2024-11-14 00:52:05 -03:00

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 totalDiv = timer.createEl("div", { cls: "simple-time-tracker-timer" });
let total = totalDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" }); let total = totalDiv.createEl("span", { cls: "simple-time-tracker-timer-time", text: "0s" });
totalDiv.createEl("span", { text: "Total" }); 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) { if (tracker.entries.length > 0) {
// add table // 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 { export function getTotalDuration(entries: Entry[]): number {
let ret = 0; let ret = 0;
for (let entry of entries) for (let entry of entries)
@ -152,6 +175,13 @@ export function getTotalDuration(entries: Entry[]): number {
return ret; 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 { export function isRunning(tracker: Tracker): boolean {
return !!getRunningEntry(tracker.entries); return !!getRunningEntry(tracker.entries);
} }