Skip to content

Commit

Permalink
Ensure periods are sorted correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoferlund committed Sep 22, 2023
1 parent 129165f commit d3c0009
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/frontend/src/model/periods/periods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ export const SinglePeriodByDate = selectorFamily({
({ get }): PeriodDetailsDto | undefined => {
const allPeriods = get(AllPeriods);
if (!allPeriods || !anyDate) return undefined;
return allPeriods
.slice()
.reverse()

return [...allPeriods]
.sort((a, b) => {
return new Date(a.endDate).getTime() - new Date(b.endDate).getTime();
})
.find((period) => new Date(period.endDate) > new Date(anyDate));
},
});
Expand Down

0 comments on commit d3c0009

Please sign in to comment.