mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-15 23:13:12 +01:00
some slight refactoring
This commit is contained in:
parent
897e6d1225
commit
3facc490bb
2 changed files with 12 additions and 17 deletions
|
@ -110,8 +110,7 @@ export function displayTracker(tracker: Tracker, element: HTMLElement, getSectio
|
|||
}
|
||||
setCountdownValues(tracker, current, total, currentDiv);
|
||||
}, 1000);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
function getCountdownDisplay(duration: moment.Duration): string {
|
||||
let ret = "";
|
||||
|
@ -126,17 +125,15 @@ function getCountdownDisplay(duration: moment.Duration): string {
|
|||
function setCountdownValues(tracker: Tracker, current: HTMLElement, total: HTMLElement, currentDiv: HTMLDivElement) {
|
||||
let currEntry = tracker.entries.last();
|
||||
if (currEntry) {
|
||||
if (!currEntry.endTime) {
|
||||
let currDuration = moment().diff(moment.unix(currEntry.startTime));
|
||||
if (!currEntry.endTime)
|
||||
current.setText(getCountdownDisplay(moment.duration(currDuration)));
|
||||
}
|
||||
|
||||
let totalDuration = 0;
|
||||
for (let entry of tracker.entries) {
|
||||
if (entry == currEntry && !currEntry.endTime) {
|
||||
totalDuration += currDuration;
|
||||
} else {
|
||||
totalDuration += moment.unix(entry.endTime).diff(moment.unix(entry.startTime));
|
||||
}
|
||||
let endTime = entry.endTime ? moment.unix(entry.endTime) : moment();
|
||||
totalDuration += endTime.diff(moment.unix(entry.startTime));
|
||||
}
|
||||
total.setText(getCountdownDisplay(moment.duration(totalDuration)));
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue