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); setCountdownValues(tracker, current, total, currentDiv);
}, 1000); }, 1000);
}
};
function getCountdownDisplay(duration: moment.Duration): string { function getCountdownDisplay(duration: moment.Duration): string {
let ret = ""; let ret = "";
@ -126,17 +125,15 @@ function getCountdownDisplay(duration: moment.Duration): string {
function setCountdownValues(tracker: Tracker, current: HTMLElement, total: HTMLElement, currentDiv: HTMLDivElement) { function setCountdownValues(tracker: Tracker, current: HTMLElement, total: HTMLElement, currentDiv: HTMLDivElement) {
let currEntry = tracker.entries.last(); let currEntry = tracker.entries.last();
if (currEntry) { if (currEntry) {
let currDuration = moment().diff(moment.unix(currEntry.startTime)); if (!currEntry.endTime) {
if (!currEntry.endTime) let currDuration = moment().diff(moment.unix(currEntry.startTime));
current.setText(getCountdownDisplay(moment.duration(currDuration))); current.setText(getCountdownDisplay(moment.duration(currDuration)));
}
let totalDuration = 0; let totalDuration = 0;
for (let entry of tracker.entries) { for (let entry of tracker.entries) {
if (entry == currEntry && !currEntry.endTime) { let endTime = entry.endTime ? moment.unix(entry.endTime) : moment();
totalDuration += currDuration; totalDuration += endTime.diff(moment.unix(entry.startTime));
} else {
totalDuration += moment.unix(entry.endTime).diff(moment.unix(entry.startTime));
}
} }
total.setText(getCountdownDisplay(moment.duration(totalDuration))); total.setText(getCountdownDisplay(moment.duration(totalDuration)));
} }

File diff suppressed because one or more lines are too long