diff --git a/components/src/query/queryRelativeGrowthAdvantage.ts b/components/src/query/queryRelativeGrowthAdvantage.ts index f93623a6..558fcadb 100644 --- a/components/src/query/queryRelativeGrowthAdvantage.ts +++ b/components/src/query/queryRelativeGrowthAdvantage.ts @@ -28,12 +28,10 @@ export async function queryRelativeGrowthAdvantage d.date)); - if (!min && !max) { + const { min: minDate, max: maxDate } = getMinMaxTemporal(denominatorData.content.map((d) => d.date)); + if (!minDate && !maxDate) { return null; } - const minDate = min as YearMonthDay; - const maxDate = max as YearMonthDay; const numeratorCounts = new Map(); numeratorData.content.forEach((d) => { diff --git a/components/src/utils/temporal.ts b/components/src/utils/temporal.ts index b920bdb5..0810fee4 100644 --- a/components/src/utils/temporal.ts +++ b/components/src/utils/temporal.ts @@ -345,9 +345,9 @@ export function compareTemporal(a: Temporal | null, b: Temporal | null): number return 0; } -export function getMinMaxTemporal(values: Iterable) { - let min = null; - let max = null; +export function getMinMaxTemporal(values: Iterable) { + let min: T | null = null; + let max: T | null = null; for (const value of values) { if (value === null) { continue;