Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
⏳ Fantastic cron parser and constructor.
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
JSR Score
100%
Published
2 months ago (0.3.3)
import { head } from "jsr:@coven/iterables@^0.3.3"; import type { Maybe } from "jsr:@coven/types@^0.3.3"; import type { CronObject } from "./CronObject.ts"; import type { CronString } from "./CronString.ts"; import { nextDates } from "./nextDates.ts"; /** * Get next ISO date string for the given date and the given cron expression. * * @example * ```typescript * nextDate(new Date("1989-10-13T10:15:00.000"))("* * * * *"); // Date("1989-10-13T10:16:00.000") * ``` * @param date Base date to get the next date from. * @returns Curried function with date set. */ export const nextDate = ( date: Readonly<Date>, ): (cron: CronString | Partial<CronObject>) => Maybe<Date> => { const nextDatesFor = nextDates(date); return (cron) => head(nextDatesFor(cron)); };