From d56f3b0f9706c736aeedba8fa57d6bc92677c952 Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Fri, 21 Aug 2026 19:35:15 +0530 Subject: [PATCH] fix(reports): parse DD-MM-YYYY dates strictly in period merges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit new Date() mis-read DD-MM-YYYY as MM-DD-YYYY, so multi-bucket periods (e.g. merged inflow+outflow slices) re-derived cadence from garbage dates — Aug Zomato showed 12.89 days instead of 0.76. Use the strict parseOccurredAt() in the cadence branch and dateVal() so first/last date merges order correctly too. --- src/Reports/types.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Reports/types.ts b/src/Reports/types.ts index 7d07808..6873573 100644 --- a/src/Reports/types.ts +++ b/src/Reports/types.ts @@ -1,4 +1,5 @@ import type { FieldConfig, ResourceConfig } from "../../react-openapi"; +import { parseOccurredAt } from "../common/utils/dates"; export interface PeriodMetricsVM { outflows: number; @@ -79,8 +80,11 @@ export function metricLabels(schemas: Record): MetricLabel[] { } function dateVal(value: string): number { - const t = new Date(value).getTime(); - return Number.isNaN(t) ? 0 : t; + try { + return parseOccurredAt(value).getTime(); + } catch { + return 0; + } } function bucketMatches(bucket: any, filter: SliceFilter): boolean { @@ -175,7 +179,13 @@ export function buildPeriodGroups(buckets: any[], filter: SliceFilter): ReportPe vm.avg = vm.count ? Math.round((vm.sum / vm.count) * 100) / 100 : null; if (acc.sources > 1) { const dates = acc.txns - .map((t) => new Date(t?.occurred_at ?? "").getTime()) + .map((t) => { + try { + return parseOccurredAt(t?.occurred_at).getTime(); + } catch { + return NaN; + } + }) .filter((t) => !Number.isNaN(t)) .sort((a, b) => a - b); if (dates.length >= 2) {