diff --git a/src/pages/internal/import.tsx b/src/pages/internal/import.tsx index f25fe84fde5d4a86372115db933a6b82f431ed9b..ca6b0e1a62c13b15d940e7e7bf4287d92a348899 100644 --- a/src/pages/internal/import.tsx +++ b/src/pages/internal/import.tsx @@ -55,14 +55,23 @@ function TerminBody({ return (event: ICalEvent) => !nCi(event); }; + const sortEvents = (a: ICalEvent, b: ICalEvent) => { + if (a.startDate === undefined || b.startDate === undefined) { + return 0; + } + return a.startDate.toMillis() - b.startDate.toMillis(); + }; + // find events that are new (place, duration and time unique) const new_events = imported_events.current .filter(notContainedIn(existingEvents)) - .filter(removeDuplicates); + .filter(removeDuplicates) + .sort(sortEvents); // find existing events that are not in the imported events const not_imported_events = existingEvents .filter(notContainedIn(imported_events.current)) - .filter(removeDuplicates); + .filter(removeDuplicates) + .sort(sortEvents); // events that are in both const full_matches = imported_events.current .filter(containedIn(existingEvents))