( tasks: TaskInfo[], getActiveSession: (task: TaskInfo) => TimeEntry | null )
| 91 | } |
| 92 | |
| 93 | export function computeActiveTimeSessions( |
| 94 | tasks: TaskInfo[], |
| 95 | getActiveSession: (task: TaskInfo) => TimeEntry | null |
| 96 | ): ActiveSessionsResult { |
| 97 | const activeSessions: ActiveSessionInfo[] = []; |
| 98 | |
| 99 | for (const task of tasks) { |
| 100 | const activeEntry = getActiveSession(task); |
| 101 | if (activeEntry) { |
| 102 | const startTime = new Date(activeEntry.startTime); |
| 103 | const elapsedMinutes = Math.floor( |
| 104 | (Date.now() - startTime.getTime()) / (1000 * 60) |
| 105 | ); |
| 106 | |
| 107 | activeSessions.push({ |
| 108 | task: { |
| 109 | id: task.path, |
| 110 | title: task.title, |
| 111 | status: task.status, |
| 112 | priority: task.priority, |
| 113 | tags: task.tags || [], |
| 114 | projects: task.projects || [], |
| 115 | }, |
| 116 | session: { |
| 117 | startTime: activeEntry.startTime, |
| 118 | description: activeEntry.description, |
| 119 | elapsedMinutes, |
| 120 | }, |
| 121 | elapsedMinutes, |
| 122 | }); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return { |
| 127 | activeSessions, |
| 128 | totalActiveSessions: activeSessions.length, |
| 129 | totalElapsedMinutes: activeSessions.reduce( |
| 130 | (sum, session) => sum + session.elapsedMinutes, |
| 131 | 0 |
| 132 | ), |
| 133 | }; |
| 134 | } |
| 135 | |
| 136 | function computeDateRange(options: TimeSummaryOptions): { startDate: Date; endDate: Date } { |
| 137 | let startDate: Date; |
no test coverage detected