diff --git a/src/services/MCPService.ts b/src/services/MCPService.ts index ea70a875..73f523aa 100644 --- a/src/services/MCPService.ts +++ b/src/services/MCPService.ts @@ -526,7 +526,7 @@ export class MCPService { "tasknotes_get_time_summary", "Get time tracking summary for a period", { - period: z.enum(["today", "week", "month", "all"]).optional().describe("Time period (default: today)"), + period: z.enum(["today", "week", "month", "all", "custom"]).optional().describe("Time period (default: today)"), from: z.string().optional().describe("Start date (ISO string) for custom range"), to: z.string().optional().describe("End date (ISO string) for custom range"), }, diff --git a/tests/unit/utils/timeTrackingUtils.test.ts b/tests/unit/utils/timeTrackingUtils.test.ts index 087392c7..cf193e7a 100644 --- a/tests/unit/utils/timeTrackingUtils.test.ts +++ b/tests/unit/utils/timeTrackingUtils.test.ts @@ -260,6 +260,40 @@ describe('timeTrackingUtils', () => { expect(result.topTags).toBeUndefined(); }); + it('should filter by custom date range when period is "custom"', () => { + const tasks: TaskInfo[] = [ + TaskFactory.createTask({ + title: 'In Range', + path: '/tasks/in-range.md', + timeEntries: [ + { startTime: '2025-03-03T10:00:00Z', endTime: '2025-03-03T10:30:00Z', duration: 30 }, + ], + }), + TaskFactory.createTask({ + title: 'Out of Range', + path: '/tasks/out-of-range.md', + timeEntries: [ + { startTime: '2025-01-01T10:00:00Z', endTime: '2025-01-01T10:30:00Z', duration: 30 }, + ], + }), + ]; + + const result = computeTimeSummary( + tasks, + { + period: 'custom', + fromDate: new Date('2025-03-01T00:00:00Z'), + toDate: new Date('2025-03-04T23:59:59Z'), + }, + isCompleted + ); + + expect(result.summary.totalMinutes).toBe(30); + expect(result.summary.tasksWithTime).toBe(1); + expect(result.topTasks).toHaveLength(1); + expect(result.topTasks[0].title).toBe('In Range'); + }); + it('should sort top tasks by minutes descending', () => { const tasks: TaskInfo[] = [ TaskFactory.createTask({