- Extract shared defaultReferencePeriod helper (src/utils/referencePeriod.ts) - useHighlights now reads ?refY=YYYY&refM=MM, defaults to previous month - getHighlights signature: (referenceYear, referenceMonth, ytdYear, windowDays, ...) - YTD tile pinned to Jan 1 of current civil year, independent of reference month - CompareReferenceMonthPicker surfaced on /reports/highlights - Hub highlights panel inherits the same default via useHighlights - useCartes and useCompare now delegate their default-period helpers to the shared util
16 lines
598 B
TypeScript
16 lines
598 B
TypeScript
/**
|
|
* Shared helper used by reports that pivot on a reference month
|
|
* (Highlights, Compare, Cartes). Returns the calendar month immediately
|
|
* preceding `today` — January wraps to December of the previous year.
|
|
*
|
|
* Kept as a pure function so every consumer can unit-test its own wiring
|
|
* with a deterministic `today` override.
|
|
*/
|
|
export function defaultReferencePeriod(
|
|
today: Date = new Date(),
|
|
): { year: number; month: number } {
|
|
const y = today.getFullYear();
|
|
const m = today.getMonth() + 1;
|
|
if (m === 1) return { year: y - 1, month: 12 };
|
|
return { year: y, month: m - 1 };
|
|
}
|