From 1edfec96569f3e9b70dae4e858a301e148251c21 Mon Sep 17 00:00:00 2001 From: Manuel Rauber Date: Mon, 2 Sep 2024 07:08:05 +0200 Subject: [PATCH] feat: sort by date then by start time --- src/app/services/time-tracking/time.table.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/services/time-tracking/time.table.ts b/src/app/services/time-tracking/time.table.ts index 1c56deb..1dde353 100644 --- a/src/app/services/time-tracking/time.table.ts +++ b/src/app/services/time-tracking/time.table.ts @@ -62,7 +62,15 @@ export class TimeTable implements DatabaseTable { private async items(fromTimestamp: Milliseconds = 0, toTimestamp: Milliseconds = Number.MAX_SAFE_INTEGER): Promise { 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) })); } }