fix(api): use UTC methods in defaultFrom/defaultTo date helpers
The server-side date fallback helpers used local-timezone JS Date methods (setDate/setHours), creating a mismatch when clients send explicit UTC dates (e.g. 2026-02-28T00:00:00Z). Changed to UTC methods (setUTCDate/setUTCHours) to ensure consistent UTC behavior. Also fixed the 90-day churn-risk lookback to use UTC consistently. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -31,14 +31,14 @@ function parseDate(value: string | undefined, fallback: Date): Date {
|
||||
|
||||
function defaultFrom(): Date {
|
||||
const d = new Date();
|
||||
d.setDate(d.getDate() - 30);
|
||||
d.setHours(0, 0, 0, 0);
|
||||
d.setUTCDate(d.getUTCDate() - 30);
|
||||
d.setUTCHours(0, 0, 0, 0);
|
||||
return d;
|
||||
}
|
||||
|
||||
function defaultTo(): Date {
|
||||
const d = new Date();
|
||||
d.setHours(23, 59, 59, 999);
|
||||
d.setUTCHours(23, 59, 59, 999);
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ reportsRouter.get("/clients", async (c) => {
|
||||
|
||||
// Clients with no appointment in last 90 days (churn risk)
|
||||
const ninetyDaysAgo = new Date();
|
||||
ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90);
|
||||
ninetyDaysAgo.setUTCDate(ninetyDaysAgo.getUTCDate() - 90);
|
||||
const ninetyDaysAgoISO = ninetyDaysAgo.toISOString();
|
||||
|
||||
const churnRisk = await db
|
||||
|
||||
Reference in New Issue
Block a user