extract active maintenance window check

This commit is contained in:
Alex Holliday committed 2026-05-21 10:02:39 -07:00
1 parent 46c80985ec
commit 85196852f4
1 file changed
+28
+28
View File
@@ -0,0 +1,28 @@
import type { MaintenanceWindow } from "@/types/index.js";
export const isWindowActive = (window: MaintenanceWindow, now: Date = new Date()): boolean => {
if (!window.active) {
return false;
}
const start = new Date(window.start);
const end = new Date(window.end);
const repeatInterval = window.repeat || 0;
if (start <= now && end >= now) {
return true;
}
// For a recurring window whose first occurrence is in the past,
// advance start/end by the repeat interval until we either catch
// an occurrence covering `now` or move past it.
while (start < now && repeatInterval !== 0) {
start.setTime(start.getTime() + repeatInterval);
end.setTime(end.getTime() + repeatInterval);
if (start <= now && end >= now) {
return true;
}
}
return false;
};