MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / parseRange

Function parseRange

telemetry-dashboard/src/api.ts:97–116  ·  view source on GitHub ↗

* The range every endpoint shares. Absent params default to the last 30 days * ending today, which is also what the dashboard's presets send.

(url: URL)

Source from the content-addressed store, hash-verified

95 * ending today, which is also what the dashboard's presets send.
96 */
97function parseRange(url: URL): Range | ApiResult {
98 const rawTo = url.searchParams.get('to');
99 const rawFrom = url.searchParams.get('from');
100
101 if (rawTo !== null && !isValidDay(rawTo)) return fail('to must be YYYY-MM-DD');
102 if (rawFrom !== null && !isValidDay(rawFrom)) return fail('from must be YYYY-MM-DD');
103
104 const to = rawTo ?? utcDay(Date.now());
105 const from = rawFrom ?? addDays(to, -(DEFAULT_RANGE_DAYS - 1));
106 if (from > to) return fail('from must not be after to');
107
108 const requested = daysApart(from, to) + 1;
109 const clamped = requested > MAX_RANGE_DAYS;
110 return {
111 from: clamped ? addDays(to, -(MAX_RANGE_DAYS - 1)) : from,
112 to,
113 days: clamped ? MAX_RANGE_DAYS : requested,
114 clamped,
115 };
116}
117
118const isApiResult = (v: Range | ApiResult): v is ApiResult => 'body' in v;
119

Callers 1

handleApiFunction · 0.85

Calls 6

daysApartFunction · 0.85
isValidDayFunction · 0.70
failFunction · 0.70
utcDayFunction · 0.70
addDaysFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected