effect-io-ai

Package: effect
Module: Cron

Cron.next

Returns the next scheduled date/time for the given Cron instance.

When to use

Use to find the next occurrence of a cron schedule after a specific date/time or after the current time.

Details

Searches for the next date and time when the cron schedule should trigger, starting after the specified date/time or after the current time when no date is provided.

Example (Finding the next occurrence)

import { Cron, Result } from "effect"

const cron = Result.getOrThrow(Cron.parse("0 0 4 8-14 * *", "UTC"))

// Get next run after a specific date
const after = new Date("2021-01-01T00:00:00Z")
const nextRun = Cron.next(cron, after)
console.log(nextRun.toISOString()) // 2021-01-08T04:00:00.000Z

// Get next run from current time
const nextFromNow = Cron.next(cron)
console.log(nextFromNow) // Next occurrence from now

See

Signature

declare const next: (cron: Cron, now?: DateTime.DateTime.Input) => Date

Source

Since v2.0.0