mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-21 17:23:28 +01:00
Compare commits
3 commits
cc0d336d96
...
ff48e05403
Author | SHA1 | Date | |
---|---|---|---|
|
ff48e05403 | ||
|
8aa3143793 | ||
|
d4188127b3 |
1 changed files with 30 additions and 0 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue