diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index f3353be3b2..ec6c2bf304 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -1079,13 +1079,13 @@ describe.each([ !isInternal && describe("datetime - time only", () => { - const T_1000 = "10:00" - const T_1045 = "10:45" - const T_1200 = "12:00" - const T_1530 = "15:30" - const T_0000 = "00:00" + const T_1000 = "10:00:00" + const T_1045 = "10:45:00" + const T_1200 = "12:00:00" + const T_1530 = "15:30:00" + const T_0000 = "00:00:00" - const UNEXISTING_TIME = "10:01" + const UNEXISTING_TIME = "10:01:00" const NULL_TIME__ID = `null_time__id` diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 1699d28b5e..a773524ae4 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -519,18 +519,29 @@ export const sort = ( if (!sort || !sortOrder || !sortType) { return docs } - const parse = - sortType === "string" ? (x: any) => `${x}` : (x: string) => parseFloat(x) + + const parse = (x: any) => { + if (x == null) { + return x + } + if (sortType === "string") { + return `${x}` + } + return parseFloat(x) + } + return docs .slice() .sort((a: { [x: string]: any }, b: { [x: string]: any }) => { const colA = parse(a[sort]) const colB = parse(b[sort]) + + const result = colB == null || colA > colB ? 1 : -1 if (sortOrder.toLowerCase() === "descending") { - return colA > colB ? -1 : 1 - } else { - return colA > colB ? 1 : -1 + return result * -1 } + + return result }) }