mirror of
https://github.com/Ellpeck/ObsidianSimpleTimeTracker.git
synced 2024-11-16 07:23: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);
|
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
Loading…
Reference in a new issue