MCPcopy
hub / github.com/msgbyte/tianji / parseDateRange

Function parseDateRange

src/server/utils/common.ts:180–217  ·  view source on GitHub ↗
({
  websiteId,
  startAt,
  endAt,
  unit,
}: {
  websiteId: string;
  startAt: number;
  endAt: number;
  unit?: string;
})

Source from the content-addressed store, hash-verified

178}
179
180export async function parseDateRange({
181 websiteId,
182 startAt,
183 endAt,
184 unit,
185}: {
186 websiteId: string;
187 startAt: number;
188 endAt: number;
189 unit?: string;
190}) {
191 // All-time
192 if (+startAt === 0 && +endAt === 1) {
193 const { min, max } = await getWorkspaceWebsiteDateRange(
194 websiteId as string
195 );
196 const startDate = new Date(min!);
197 const endDate = new Date(max!);
198
199 return {
200 startDate,
201 endDate,
202 unit: getMinimumUnit(startDate, endDate),
203 };
204 }
205
206 const startDate = new Date(+startAt);
207 const endDate = new Date(+endAt);
208 const minUnit = getMinimumUnit(startDate, endDate);
209
210 return {
211 startDate,
212 endDate,
213 unit: (getAllowedUnits(startDate, endDate).includes(unit as string)
214 ? unit
215 : minUnit) as string,
216 };
217}
218
219export function getAllowedUnits(startDate: Date, endDate: Date) {
220 const units = ['minute', 'hour', 'day', 'month', 'year'];

Callers 1

website.tsFile · 0.85

Calls 3

getMinimumUnitFunction · 0.90
getAllowedUnitsFunction · 0.85

Tested by

no test coverage detected