MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / validateDateRange

Function validateDateRange

packages/web/src/features/git/dateUtils.ts:110–134  ·  view source on GitHub ↗
(since: string | undefined, until: string | undefined)

Source from the content-addressed store, hash-verified

108 * @returns Error message if invalid, null if valid
109 */
110export function validateDateRange(since: string | undefined, until: string | undefined): string | null {
111 if (!since || !until) {
112 return null; // No validation needed if either is missing
113 }
114
115 const parsedSince = parseTemporalDate(since);
116 const parsedUntil = parseTemporalDate(until);
117
118 if (!parsedSince || !parsedUntil) {
119 return null; // Let individual date parsing handle invalid formats
120 }
121
122 const sinceDate = new Date(parsedSince);
123 const untilDate = new Date(parsedUntil);
124
125 if (isNaN(sinceDate.getTime()) || isNaN(untilDate.getTime())) {
126 return null;
127 }
128
129 if (sinceDate > untilDate) {
130 return `Invalid date range: 'since' (${since}) must be before 'until' (${until})`;
131 }
132
133 return null;
134}
135
136/**
137 * Convert a date to a format suitable for Prisma database queries.

Callers 2

listCommitsFunction · 0.90
dateUtils.test.tsFile · 0.90

Calls 1

parseTemporalDateFunction · 0.85

Tested by

no test coverage detected