⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(time-entry): reject a start time later than the end time
Andrej99e41ad8efcd
diff --git a/apps/api/src/mcp/tools.ts b/apps/api/src/mcp/tools.tsindex 1a0489023..8f91fec97 100644--- a/apps/api/src/mcp/tools.ts+++ b/apps/api/src/mcp/tools.ts@@ -913,7 +913,7 @@ export function registerMcpTools("update_time_entry",{description:- "Update a time entry. startTime is required; omit endTime to reopen the entry.",+ "Update a time entry. startTime is required; omitting endTime keeps the stored one. startTime cannot be later than the end time.",inputSchema: z.object({id: nonEmptyString,startTime: isoDateTimeSchema,diff --git a/apps/api/src/time-entry/controllers/update-time-entry.ts b/apps/api/src/time-entry/controllers/update-time-entry.tsindex 24dfcaee8..3d4ef91fb 100644--- a/apps/api/src/time-entry/controllers/update-time-entry.ts+++ b/apps/api/src/time-entry/controllers/update-time-entry.ts@@ -26,7 +26,13 @@ async function updateTimeEntry(params: UpdateTimeEntryParams) {const effectiveEndTime = endTime ?? existingTimeEntry.endTime;- // Calculate duration if the entry has an endTime after this update.+ if (effectiveEndTime && startTime.getTime() > effectiveEndTime.getTime()) {+ throw new HTTPException(400, {+ message:+ "Start time cannot be after end time. Please adjust the time range.",+ });+ }+let duration: number | null = null;if (effectiveEndTime) {duration = Math.floor(diff --git a/packages/mcp/src/tools/register.ts b/packages/mcp/src/tools/register.tsindex eb22462cb..3131b9331 100644--- a/packages/mcp/src/tools/register.ts+++ b/packages/mcp/src/tools/register.ts@@ -742,7 +742,7 @@ export function registerTools("update_time_entry",{description:- "Update a time entry. startTime is required; omit endTime to reopen the entry.",+ "Update a time entry. startTime is required; omitting endTime keeps the stored one. startTime cannot be later than the end time.",inputSchema: z.object({id: nonEmptyString,startTime: isoDateTimeSchema,diff --git a/tests/api/time-entry/update-time-entry.test.ts b/tests/api/time-entry/update-time-entry.test.tsindex 091d39c57..d1a0d06aa 100644--- a/tests/api/time-entry/update-time-entry.test.ts+++ b/tests/api/time-entry/update-time-entry.test.ts@@ -70,4 +70,83 @@ describe("updateTimeEntry", () => {description: "renamed",});});++ it("rejects a startTime later than the preserved endTime", async () => {+ const updateChain = makeUpdateMock({});++ mockSelect.mockReturnValue(+ makeSelectMock([+ {+ id: "time-entry-1",+ startTime: new Date("2026-08-10T10:00:00.000Z"),+ endTime: new Date("2026-08-10T11:00:00.000Z"),+ duration: 3600,+ },+ ]),+ );+ mockUpdate.mockReturnValue(updateChain);++ await expect(+ updateTimeEntry({+ timeEntryId: "time-entry-1",+ startTime: new Date("2026-08-10T12:00:00.000Z"),+ }),+ ).rejects.toMatchObject({ status: 400 });++ expect(updateChain.set).not.toHaveBeenCalled();+ });++ it("rejects a startTime later than an endTime supplied in the same update", async () => {+ const updateChain = makeUpdateMock({});++ mockSelect.mockReturnValue(+ makeSelectMock([+ {+ id: "time-entry-1",+ startTime: new Date("2026-08-10T10:00:00.000Z"),+ endTime: null,+ duration: null,+ },+ ]),+ );+ mockUpdate.mockReturnValue(updateChain);++ await expect(+ updateTimeEntry({+ timeEntryId: "time-entry-1",+ startTime: new Date("2026-08-10T12:00:00.000Z"),+ endTime: new Date("2026-08-10T11:00:00.000Z"),+ }),+ ).rejects.toMatchObject({ status: 400 });++ expect(updateChain.set).not.toHaveBeenCalled();+ });++ it("still allows an open entry to have its startTime moved forward", async () => {+ const nextStartTime = new Date("2026-08-10T12:00:00.000Z");+ const updateChain = makeUpdateMock({ id: "time-entry-1" });++ mockSelect.mockReturnValue(+ makeSelectMock([+ {+ id: "time-entry-1",+ startTime: new Date("2026-08-10T10:00:00.000Z"),+ endTime: null,+ duration: null,+ },+ ]),+ );+ mockUpdate.mockReturnValue(updateChain);++ await updateTimeEntry({+ timeEntryId: "time-entry-1",+ startTime: nextStartTime,+ });++ expect(updateChain.set).toHaveBeenCalledWith({+ startTime: nextStartTime,+ endTime: null,+ duration: null,+ });+ });});