ProvenPin Install

cron-parser next run dates: working versions (tested 2026-10-15)

Parse cron expressions with cron-parser v5, compute next and previous run dates against a fixed currentDate and tz, iterate with take, and reject invalid expressions offline.

passed4 passed · 0 failed2026-10-15 22:58 UTC
Status
passed
Last passed
2026-10-15 22:58 UTC
Tests
4 / 4
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
cron-parser@5.10.2@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38820570375

The code

Exactly the files that passed. Your agent can pull them with get_recipe("cron-parser-next-runs") (install), or see them on GitHub.

package.json
{
  "name": "cron-parser-next-runs",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "cron-parser": "5.10.2"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/scheduler.ts
import { CronExpressionParser } from "cron-parser";

export type RunOptions = {
  currentDate: Date;
  tz?: string;
};

function interval(expression: string, options: RunOptions) {
  return CronExpressionParser.parse(expression, {
    currentDate: options.currentDate,
    tz: options.tz,
  });
}

export function nextRun(expression: string, options: RunOptions): Date {
  return interval(expression, options).next().toDate();
}

export function previousRun(expression: string, options: RunOptions): Date {
  return interval(expression, options).prev().toDate();
}

export function nextRuns(expression: string, count: number, options: RunOptions): Date[] {
  return interval(expression, options)
    .take(count)
    .map((date) => date.toDate());
}
test/scheduler.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { nextRun, previousRun, nextRuns } from "../src/scheduler.ts";

const currentDate = new Date("2024-01-01T00:07:30.000Z");

test("computes the next and previous run dates", () => {
  assert.equal(
    nextRun("*/15 * * * *", { currentDate, tz: "UTC" }).toISOString(),
    "2024-01-01T00:15:00.000Z",
  );
  assert.equal(
    previousRun("*/15 * * * *", { currentDate, tz: "UTC" }).toISOString(),
    "2024-01-01T00:00:00.000Z",
  );
});

test("iterates upcoming runs with take", () => {
  const dates = nextRuns("*/15 * * * *", 3, { currentDate, tz: "UTC" });
  assert.deepEqual(
    dates.map((d) => d.toISOString()),
    [
      "2024-01-01T00:15:00.000Z",
      "2024-01-01T00:30:00.000Z",
      "2024-01-01T00:45:00.000Z",
    ],
  );
});

test("honours the tz option when resolving a daily schedule", () => {
  const next = nextRun("0 9 * * *", { currentDate, tz: "America/New_York" });
  assert.equal(next.toISOString(), "2024-01-01T14:00:00.000Z");
});

test("rejects an invalid cron expression", () => {
  assert.throws(() => nextRun("61 * * * *", { currentDate, tz: "UTC" }), Error);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.