agentsclimarketplace

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

Install
npx -y skills add kjuhwa/skills-hub --skill cron-matcher-with-croner-nextrun

Assembled 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/Budapest vs UTC).
  • Don't want to write your own cron expression parser.

How it works

  1. Use croner: new Cron(expr, { timezone }).
  2. Floor the current Date to the start of its minute (setSeconds(0, 0)).
  3. Ask croner nextRun(startOfMinute - 1s) - "when is the next fire after the last second of the previous minute?".
  4. If that nextRun timestamp lies inside [startOfMinute, startOfMinute + 60_000), it matches this minute.
  5. 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.

Keep looking

Skills are one crate of 326,149. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.