Cron module provides utilities for parsing and working with cron expressions. A Cron instance defines when a scheduled task should run, supporting seconds, minutes, hours, days, months, and weekdays constraints with timezone-aware scheduling.
Overview
Cron expressions provide a flexible way to define recurring schedules:- Standard cron format - 5 or 6 field expressions
- Named time zones - IANA timezone support
- DST handling - Automatic daylight saving time adjustments
- Next occurrence - Calculate next scheduled time
- Validation - Type-safe parsing with error handling
Creating Cron Schedules
Parsing Cron Expressions
Parse standard cron expressions.Unsafe Parsing
Parse cron expressions, throwing on error.Manual Construction
Construct cron schedules programmatically.Cron Expression Format
Standard Format
Common Examples
Cron Syntax Features
Wildcards
Match all values.Lists
Specify multiple values.Ranges
Specify a range of values.Steps
Specify intervals.Month and Day Names
Use named values.Working with Time Zones
Named Time Zones
Use IANA time zone identifiers.DST Handling
Cron automatically handles daylight saving time transitions.Checking Schedule Matches
Determine if a date matches the schedule.Getting Next Occurrence
Calculate the next scheduled time.Generating Sequences
Create an iterator of scheduled dates.Using with Schedule
Integrate cron schedules with Effect schedules.Common Patterns
Daily Tasks
Weekly Tasks
Monthly Tasks
Business Hours
Error Handling
Parse Errors
Handle parsing errors gracefully.Safe Operations
Comparing Cron Schedules
API Reference
Types
Constructors
parse(cron: string, tz?: string | TimeZone): Result<Cron, CronParseError>parseUnsafe(cron: string, tz?: string | TimeZone): Cronmake(values: CronValues): Cron
Operations
match(cron: Cron, date: DateTime.Input): booleannext(cron: Cron, now?: DateTime.Input): Datesequence(cron: Cron, now?: DateTime.Input): IterableIterator<Date>
Guards
isCron(u: unknown): u is CronisCronParseError(u: unknown): u is CronParseError
Comparison
equals(self: Cron, that: Cron): booleanEquivalence: Equivalence<Cron>
