Skip to content

Commit 1c9d32f

Browse files
fix(shared): composer # suggestions sort by update instant, not timestamp text (pingdotgg#35137)
1 parent 51b1858 commit 1c9d32f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎packages/shared/src/composerPullRequestMatches.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ describe("filterComposerPullRequestMatches", () => {
2626
});
2727
expect(result.map((match) => match.number)).toEqual([123, 1234, 1230]);
2828
});
29+
30+
it("orders by update instant when timestamps carry different UTC offsets", () => {
31+
const result = filterComposerPullRequestMatches({
32+
entries: [entry(401, "2026-10-25T02:50:00+02:00"), entry(499, "2026-10-25T02:10:00+01:00")],
33+
projectId: "p1",
34+
repository: "owner/repo",
35+
query: "4",
36+
limit: 1,
37+
});
38+
expect(result.map((match) => match.number)).toEqual([499]);
39+
});
2940
});
3041

3142
describe("linked pull requests", () => {

‎packages/shared/src/composerPullRequestMatches.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ export function filterComposerPullRequestMatches<
6363
}
6464
const isExactMatch = (entry: ComposerPullRequestMatch) => String(entry.number) === input.query;
6565
const isLinked = (entry: ComposerPullRequestMatch) => linkedKeys.has(keyOf(entry));
66+
const updatedAtMs = (entry: ComposerPullRequestMatch) => Date.parse(entry.updatedAt) || 0;
6667
// Hermes has no ES2023 array methods, so sort a fresh array.
6768
return [...uniqueEntries.values()]
6869
.sort(
6970
(left, right) =>
7071
Number(isExactMatch(right)) - Number(isExactMatch(left)) ||
7172
Number(isLinked(right)) - Number(isLinked(left)) ||
72-
right.updatedAt.localeCompare(left.updatedAt),
73+
updatedAtMs(right) - updatedAtMs(left),
7374
)
7475
.slice(0, input.limit);
7576
}

0 commit comments

Comments
 (0)