Skip to content

Commit

Permalink
feat: sort by date then by start time
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelRauber committed Sep 2, 2024
1 parent bd249f3 commit 1edfec9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/app/services/time-tracking/time.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ export class TimeTable implements DatabaseTable<TimeEntry> {

private async items(fromTimestamp: Milliseconds = 0, toTimestamp: Milliseconds = Number.MAX_SAFE_INTEGER): Promise<TimeEntryWithDuration[]> {
const items = await this.times.where('utcDate').between(fromTimestamp, toTimestamp, true).toArray();
items.sort((a, b) => (a.utcDate < b.utcDate ? 1 : a.utcDate > b.utcDate ? -1 : 0));
items.sort((a, b) => {
if (a.utcDate < b.utcDate) {
return 1;
} else if (a.utcDate > b.utcDate) {
return -1;
}

return a.start < b.start ? 1 : a.start > b.start ? -1 : 0;
});
return items.map(item => ({ ...item, duration: calculateDuration(item) }));
}
}

0 comments on commit 1edfec9

Please sign in to comment.