Files
frigate/web/src/utils/timelineUtil.tsx
T
Josh HawkinsandGitHub caa6edecac Migrate web to ESLint 10 flat config (#24326)
* migrate web to eslint 10 flat config

ESLint 10 dropped `.eslintrc` support, so `.eslintrc.cjs` is replaced with `eslint.config.js` and the lint scripts no longer pass `--ext` or `--ignore-path`. typescript-eslint moves to 8, react-hooks to 7, and react-refresh to 0.5, and the unused jest and vitest-globals plugins are removed. Lint behaves as it did before: catch variables aren't checked, unused disable directives aren't reported, and rules newly added to the recommended sets are off until the code passes them. typescript-eslint 8 flags constants used only in `typeof`, so those are now exported, or replaced with a union type where the export would trip react-refresh.

* fix lint findings from the eslint 10 recommended rules

Remove the rule overrides from the flat config migration and fix what they were hiding. Unused catch bindings are dropped, 20 disable directives that suppressed nothing are removed (react-hooks 5.2 and 7.1.1 report identical exhaustive-deps findings with inline config ignored), dead initial values are dropped, short-circuit calls become if statements or optional calls, rethrown errors pass `cause`, and the disabled "No recordings" tooltip in `ReviewTimeline` is removed along with its memo and the `getRecordingAvailability` prop. The 3 react-refresh warnings for files that export contexts or classes are left for a later refactor.
2026-09-14 07:53:45 -06:00

85 lines
2.2 KiB
TypeScript

import { endOfHourOrCurrentTime } from "./dateUtil";
import { TimeRange } from "@/types/timeline";
/**
*
* @param timeRange
* @returns timeRange chunked into individual hours
*/
export function getChunkedTimeDay(timeRange: TimeRange): TimeRange[] {
const endOfThisHour = new Date(timeRange.before * 1000);
endOfThisHour.setSeconds(0, 0);
const data: TimeRange[] = [];
const startDay = new Date(timeRange.after * 1000);
startDay.setUTCMinutes(0, 0, 0);
let start = startDay.getTime() / 1000;
for (let i = 0; i < 24; i++) {
startDay.setHours(startDay.getHours() + 1);
if (startDay > endOfThisHour) {
break;
}
const end = endOfHourOrCurrentTime(startDay.getTime() / 1000);
data.push({
after: start,
before: end,
});
start = startDay.getTime() / 1000;
}
data.push({
after: start,
before: Math.floor(timeRange.before),
});
return data;
}
/**
* Find the chunk index that contains the given timestamp.
* Uses half-open intervals [after, before) for all chunks except the last,
* which uses a closed interval [after, before] so the terminal boundary
* is always reachable.
*/
export function findChunkIndex(chunks: TimeRange[], timestamp: number): number {
return chunks.findIndex((chunk, i) => {
const isLast = i === chunks.length - 1;
return (
chunk.after <= timestamp &&
(isLast ? chunk.before >= timestamp : chunk.before > timestamp)
);
});
}
export function getChunkedTimeRange(
startTimestamp: number,
endTimestamp: number,
) {
const endOfThisHour = new Date();
endOfThisHour.setHours(endOfThisHour.getHours() + 1, 0, 0, 0);
const data: TimeRange[] = [];
const startDay = new Date(startTimestamp * 1000);
startDay.setUTCMinutes(0, 0, 0);
let start = startDay.getTime() / 1000;
let end = 0;
while (end < endTimestamp) {
startDay.setHours(startDay.getHours() + 1);
if (startDay > endOfThisHour) {
break;
}
end = endOfHourOrCurrentTime(startDay.getTime() / 1000);
data.push({
after: start,
before: end,
});
start = startDay.getTime() / 1000;
}
return { start: startTimestamp, end: endTimestamp, ranges: data };
}