Skip to content

Commit

Permalink
Merge pull request #451 from jaimeferj/bugfix/parseDatesOnSort
Browse files Browse the repository at this point in the history
Fixes issue #441: Dates were not parsed on sorting
  • Loading branch information
eliandoran authored Oct 10, 2024
2 parents 469c1ce + 270aa52 commit 0ec3232
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/services/search/expressions/order_by_and_limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ class OrderByAndLimitExp extends Expression {
return larger;
}


// if both are dates, then parse them for dates comparison
if (typeof valA === "string" && this.isDate(valA) &&
typeof valB === "string" && this.isDate(valB)) {
valA = new Date(valA);

Check failure on line 75 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile.alpine)

Type 'Date' is not assignable to type 'string | number | null'.

Check failure on line 75 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile)

Type 'Date' is not assignable to type 'string | number | null'.
valB = new Date(valB);

Check failure on line 76 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile.alpine)

Type 'Date' is not assignable to type 'string | number | null'.

Check failure on line 76 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile)

Type 'Date' is not assignable to type 'string | number | null'.
}

// if both are numbers, then parse them for numerical comparison
if (typeof valA === "string" && this.isNumber(valA) &&
else if (typeof valA === "string" && this.isNumber(valA) &&
typeof valB === "string" && this.isNumber(valB)) {
valA = parseFloat(valA);
valB = parseFloat(valB);
Expand Down Expand Up @@ -99,6 +107,10 @@ class OrderByAndLimitExp extends Expression {
return noteSet;
}

isDate(date: number | string) {
return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date));

Check failure on line 111 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile.alpine)

This comparison appears to be unintentional because the types 'Date' and 'string' have no overlap.

Check failure on line 111 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile.alpine)

Argument of type 'Date' is not assignable to parameter of type 'number'.

Check failure on line 111 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile)

This comparison appears to be unintentional because the types 'Date' and 'string' have no overlap.

Check failure on line 111 in src/services/search/expressions/order_by_and_limit.ts

View workflow job for this annotation

GitHub Actions / Check Docker build (Dockerfile)

Argument of type 'Date' is not assignable to parameter of type 'number'.
}

isNumber(x: number | string) {
if (typeof x === 'number') {
return true;
Expand Down

0 comments on commit 0ec3232

Please sign in to comment.