Cron matcher with croner nextrun
Skill kjuhwa/skills-hub/skills/automation/cron-matcher-with-croner-nextrun
Implement minute-granularity cron matching by asking croner for the next run from 1 second before the current minute and checking if it falls inside the current minute.From its SKILL.md
npx -y skills add kjuhwa/skills-hub --skill cron-matcher-with-croner-nextrunAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.6 KB, 504 tokens by cl100k_base, as published. Nobody here has run it
Minute-granularity cron matching with croner
When to use
- You tick a scheduler every minute (or irregularly) and need to ask "does this cron fire right now?" without maintaining your own cron state.
- Need IANA timezone support (e.g.
Europe/Budapestvs UTC). - Don't want to write your own cron expression parser.
How it works
- Use
croner:new Cron(expr, { timezone }). - Floor the current
Dateto the start of its minute (setSeconds(0, 0)). - Ask croner
nextRun(startOfMinute - 1s)- "when is the next fire after the last second of the previous minute?". - If that
nextRuntimestamp lies inside[startOfMinute, startOfMinute + 60_000), it matches this minute. - Return false on parse error rather than throw - a malformed user cron shouldn't crash the scheduler.
Example
import { Cron } from 'croner';
export function matchesCron(expr: string, timezone?: string): boolean {
try {
const job = new Cron(expr, timezone ? { timezone } : {});
const now = new Date();
const startOfMinute = new Date(now); startOfMinute.setSeconds(0, 0);
const checkFrom = new Date(startOfMinute.getTime() - 1000);
const nextRun = job.nextRun(checkFrom);
if (!nextRun) return false;
return nextRun.getTime() >= startOfMinute.getTime()
&& nextRun.getTime() < startOfMinute.getTime() + 60_000;
} catch {
return false;
}
}
Gotchas
- "Check from 1s before" is crucial - if you ask
nextRun(startOfMinute), croner returns the NEXT fire, not the one inside the current minute. - If your scheduler tick is more frequent than once per minute, you'll match multiple times within the same minute; dedupe by logging last-fired minute per cron expr.
- IANA zone names are case-sensitive; validate against
Intl.supportedValuesOf('timeZone')before storing user config. - Don't use 6-field (seconds) cron with this pattern - the +60s window assumption breaks.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.