Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/tools/task/list-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,19 @@ function sortTasks(
break;
}
case "createdTime": {
// Use sortOrder as proxy for creation time
const orderA = a.sortOrder ?? 0;
const orderB = b.sortOrder ?? 0;
comparison = orderA - orderB;
// Extract timestamp from MongoDB ObjectID (first 8 hex chars)
// The sortOrder field values exceed JavaScript's safe integer range (2^53),
// causing precision loss during arithmetic operations.
// ObjectID's first 8 hex characters represent a Unix timestamp.
const getTimestampFromId = (id: string | undefined): number => {
if (typeof id === 'string' && id.length >= 8) {
return parseInt(id.substring(0, 8), 16);
}
return 0;
};
const timeA = getTimestampFromId(a.id);
const timeB = getTimestampFromId(b.id);
comparison = timeA - timeB;
break;
}
}
Expand Down