Skip to content

Commit c52f95c

Browse files
committed
fix: finished events sorted by start were shown at the bottom
fix #1258
1 parent 0a86dad commit c52f95c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/functions/sort_events.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,19 @@ export default function sortEvents(events: EventClass[], config) {
7474
return timeDiffA - timeDiffB;
7575
}
7676
});
77+
// Move finished events to the bottom
78+
sortedEvents.sort((a, b) => {
79+
if (a.isFinished !== b.isFinished) {
80+
return a.isFinished ? 1 : -1;
81+
}
82+
// If both events are finished, sort them by their endDateTime in ascending order.
83+
if (a.isFinished) {
84+
return dayjs(a.endDateTime).isBefore(b.endDateTime) ? -1 : 1;
85+
}
86+
return 0;
87+
});
7788
}
78-
// Move finished events to the bottom
79-
sortedEvents.sort((a, b) => {
80-
if (a.isFinished !== b.isFinished) {
81-
return a.isFinished ? 1 : -1;
82-
}
83-
// If both events are finished, sort them by their endDateTime in ascending order.
84-
if (a.isFinished) {
85-
return dayjs(a.endDateTime).isBefore(b.endDateTime) ? -1 : 1;
86-
}
87-
return 0;
88-
});
89+
8990

9091
// If config.allDayBottom is true, add the all-day events to the end of the sorted events array.
9192
if (config.allDayBottom) {

0 commit comments

Comments
 (0)