* Parses the date range config into timeMin/timeMax values.
(sourceConfig: Record<string, unknown>)
| 165 | * Parses the date range config into timeMin/timeMax values. |
| 166 | */ |
| 167 | function getTimeRange(sourceConfig: Record<string, unknown>): { timeMin: string; timeMax: string } { |
| 168 | const dateRange = (sourceConfig.dateRange as string) || 'default' |
| 169 | |
| 170 | const now = new Date() |
| 171 | |
| 172 | switch (dateRange) { |
| 173 | case 'past_only': { |
| 174 | const past = new Date(now) |
| 175 | past.setDate(past.getDate() - DEFAULT_RANGE_DAYS) |
| 176 | return { timeMin: past.toISOString(), timeMax: now.toISOString() } |
| 177 | } |
| 178 | case 'future_only': { |
| 179 | const future = new Date(now) |
| 180 | future.setDate(future.getDate() + DEFAULT_RANGE_DAYS) |
| 181 | return { timeMin: now.toISOString(), timeMax: future.toISOString() } |
| 182 | } |
| 183 | case 'past_90': { |
| 184 | const past = new Date(now) |
| 185 | past.setDate(past.getDate() - 90) |
| 186 | const future = new Date(now) |
| 187 | future.setDate(future.getDate() + 90) |
| 188 | return { timeMin: past.toISOString(), timeMax: future.toISOString() } |
| 189 | } |
| 190 | default: |
| 191 | return getDefaultTimeRange() |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Converts a CalendarEvent to an ExternalDocument. |
no test coverage detected