mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-29 00:01:42 +08:00
60f8f64481
Build versioned UTC hourly rollups, validate analytics facts, and keep dashboard requests result-only with explicit coverage semantics. Move derived metrics to the server and simplify the admin dashboard around one reconcilable UTC range without export.
16 lines
536 B
TypeScript
16 lines
536 B
TypeScript
export function statsDayKey(date: Date): string {
|
|
return date.toISOString().slice(0, 10)
|
|
}
|
|
|
|
export function utcDateStart(date: string): Date {
|
|
const value = new Date(`${date}T00:00:00.000Z`)
|
|
if (Number.isNaN(value.getTime()) || statsDayKey(value) !== date) throw new Error(`Invalid UTC date: ${date}`)
|
|
return value
|
|
}
|
|
|
|
export function addCalendarDays(date: string, days: number): string {
|
|
const value = new Date(`${date}T00:00:00.000Z`)
|
|
value.setUTCDate(value.getUTCDate() + days)
|
|
return value.toISOString().slice(0, 10)
|
|
}
|