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

Function parseRange

telemetry-dashboard/src/api.ts:105–124  ·  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

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

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