Skip to content
← Public packages

@kentcdodds/quiet-hours

Quiet hours for Kent's bots: 10 PM to 8 AM MT (DST-aware) clock, shared overnight queue, override, and the 8 AM digest of finished work and open decisions.

FollowFork

Files

status.ts

42 lines · 1.6 KB · TypeScript
import { readOverride } from './store.ts'
import { clockWindow } from './clock.ts'
import { computeStatus, isExcludedBot, parseNow } from './status-core.ts'
import type { QuietStatus } from './types.ts'

export type StatusInput = {
	/** Optional bot name. Lilly and Imogen always get `{ quiet: false, excluded: true }`. */
	bot?: string
	/** Optional ISO instant to evaluate instead of now (tests, previews). */
	now?: string
}

/**
 * Is it quiet hours right now? 10:00 PM to 8:00 AM America/Denver every day
 * (weekends included), DST-aware, with Kent's override applied.
 *
 * `until` is when the current state ends: the next 8 AM while quiet, the
 * next 10 PM while not (or the override's expiry while one is active).
 * If storage is unreachable the clock still answers and `degraded: true`
 * is set. Lilly and Imogen are excluded and always see `quiet: false`.
 *
 * @param input.bot - Optional bot name (excluded bots never go quiet)
 * @param input.now - Optional ISO instant to evaluate
 * @returns `{ quiet, until, override }` (+ `excluded` / `degraded` when relevant)
 *
 * @example
 * import status from 'kody:@kentcdodds/quiet-hours/status'
 * const s = await status()
 * // => { quiet: true, until: '2026-10-18T14:00:00.000Z', override: null }
 */
export default async function status(input: StatusInput = {}): Promise<QuietStatus> {
	const now = parseNow(input?.now)
	if (isExcludedBot(input?.bot)) {
		const window = clockWindow(now)
		return { quiet: false, until: window.until, override: null, excluded: true }
	}
	try {
		return computeStatus(now, await readOverride())
	} catch {
		return { ...computeStatus(now, null), degraded: true }
	}
}