some slight refactoring

This commit is contained in:
Ell 2022-09-28 00:52:52 +02:00
parent 897e6d1225
commit 3facc490bb
2 changed files with 12 additions and 17 deletions

View file

@ -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