computeNextDueAt (schedule.ts)

threadhunt · scheduling, cron-math, time-anchor, automation

Per-topic scheduling math (pure). Spread scansPerDay evenly across 24h; if a preferred timeOfDay (HH:MM) is set, anchor the daily slots to it. Returns the epoch ms of the next due run strictly after `now`. /

// Source: https://github.com/deepdotspace/threadhunt | License: MIT | Copyright 2026 deepdotspace
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Per-topic scheduling math (pure). Spread scansPerDay evenly across 24h; if a
 * preferred timeOfDay (HH:MM) is set, anchor the daily slots to it. Returns the
 * epoch ms of the next due run strictly after `now`.
 */

const DAY_MS = 24 * 60 * 60 * 1000

/** Parse "HH:MM" to minutes past midnight, or null if missing/invalid. */
function parseTimeOfDay(timeOfDay: string | null): number | null {
  if (!timeOfDay) return null
  const m = timeOfDay.match(/^(\d{1,2}):(\d{2})$/)
  if (!m) return null
  const h = parseInt(m[1], 10)
  const min = parseInt(m[2], 10)
  if (h < 0 || h > 23 || min < 0 || min > 59) return null
  return 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key