Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma strängvärde byggs med konkatenering i stället för att matcha mönstret.
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
/**
|
|
* Day arithmetic for the transactions history window (date_from .. date_to,
|
|
* both YYYY-MM-DD, evaluated in UTC).
|
|
*
|
|
* Shared by api-client.ts (the narrowing ladder) and sync.ts (recording the
|
|
* widest window a bank has accepted for an account, issue #2202). It lives in
|
|
* its own module because sync.test.ts mocks api-client wholesale: a helper
|
|
* exported from there would be undefined under test.
|
|
*/
|
|
const DAY_MS = 24 * 60 * 60 * 1000
|
|
|
|
function parseUtcDay(value: string | undefined): number | undefined {
|
|
if (!value) return undefined
|
|
const t = new Date(`${value}T00:00:00Z`).getTime()
|
|
return Number.isFinite(t) ? t : undefined
|
|
}
|
|
|
|
/**
|
|
* Whole days from dateFrom to dateTo. Undefined when either end is missing or
|
|
* unparseable, or when the window is negative: callers treat undefined as
|
|
* "no width known", never as 0.
|
|
*/
|
|
export function historyWindowDays(
|
|
dateFrom: string | undefined,
|
|
dateTo: string | undefined
|
|
): number | undefined {
|
|
const from = parseUtcDay(dateFrom)
|
|
const to = parseUtcDay(dateTo)
|
|
if (from === undefined || to === undefined) return undefined
|
|
const days = Math.round((to - from) / DAY_MS)
|
|
return days >= 0 ? days : undefined
|
|
}
|
|
|
|
/** The YYYY-MM-DD that lies `days` days before dateTo; undefined when dateTo is unparseable. */
|
|
export function dateFromDaysBefore(dateTo: string | undefined, days: number): string | undefined {
|
|
const to = parseUtcDay(dateTo)
|
|
if (to === undefined) return undefined
|
|
return new Date(to - days * DAY_MS).toISOString().split('T')[0]
|
|
}
|