Files
bare-operating-system/packages/bare-os-booter/lib/bare-os-sync-window.js
T
Raven Scott 268b46dd3a Add fifth feature word (STOCK_V5 / bits5) with ADR and capability docs.
Protocol: canonical seed RPC registry (seed-rpc-methods.js), bits5 on
capabilities, typed seed RPC errors, richer replication_queue and
staging_slot hints.

Booter: /proc host_os (bare-module on Bare, node:os on Node), sync_window,
debug.json, net_summary transport stats, HDMS hints/correlation, warm
profile reload, subprocess bridge snapshot helpers, boot policy v5 hooks,
BARE_OS_BIN_WORKER_ALLOW pattern groups, VFS symlink/union alignment, OTel
JSONL schema version 2 in var-log.

Seeder: pass staging/replication hints into seed channel; mirror kernel
init and boot policy example.

Kernel: enforce requireFeatureBits5 / requireInitJsSha256 when configured;
selftests for new proc surfaces.

CI/pretest: verify-doc-links, verify-man-coverage, verify-compat-matrix;
extend roadmap/ctx/dts verifiers. Add otel-bare-os-jsonl schema.

Docs: Wave 5 roadmap, kernel-extensions, handbook/devguide updates;
bare-module manifest tier/risk sample; bare-libs README.
2026-04-04 04:33:25 -04:00

50 lines
1.4 KiB
JavaScript

/**
* Parse `BARE_OS_REPLICATION_SYNC_WINDOWS` (UTC, `HH:MM-HH:MM` ranges, comma-separated).
* @param {Record<string, string>} env
* @returns {{ active: boolean, windows: string[], nowUtc: string, note?: string }}
*/
export function computeReplicationSyncWindow(env) {
const raw = String(env.BARE_OS_REPLICATION_SYNC_WINDOWS || '').trim()
const now = new Date()
const pad = (n) => (n < 10 ? '0' : '') + n
const nowUtc = `${pad(now.getUTCHours())}:${pad(now.getUTCMinutes())}`
if (!raw) {
return {
active: true,
windows: [],
nowUtc,
note: 'no windows; replication always allowed'
}
}
const parts = raw
.split(',')
.map((s) => s.trim())
.filter(Boolean)
/** @type {string[]} */
const windows = []
let active = false
const toMin = (h, m) => h * 60 + m
const cur = toMin(now.getUTCHours(), now.getUTCMinutes())
for (const p of parts) {
const m = p.match(/^(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})$/)
if (!m) continue
const a = toMin(Number(m[1]), Number(m[2]))
const b = toMin(Number(m[3]), Number(m[4]))
windows.push(p)
if (a <= b) {
if (cur >= a && cur <= b) active = true
} else {
if (cur >= a || cur <= b) active = true
}
}
if (windows.length === 0) {
return {
active: true,
windows: [],
nowUtc,
note: 'no valid windows parsed; default allow'
}
}
return { active, windows, nowUtc }
}