fix(reports): parse DD-MM-YYYY dates strictly in period merges
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.
This commit is contained in:
@@ -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<string, any>): 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) {
|
||||
|
||||
Reference in New Issue
Block a user