(cron: string, tz?: DateTime.TimeZone | string): CronParses a cron expression into a Cron instance, throwing on failure.
When to use
Use when you expect the input to be valid and want to avoid handling the
Result type.
Example (Parsing cron expressions unsafely)
import { Cron } from "effect"
// At 04:00 on every day-of-month from 8 through 14
const cron = Cron.parseUnsafe("0 0 4 8-14 * *")
// With timezone
const cronWithTz = Cron.parseUnsafe("0 0 9 * * *", "America/New_York")
// This would throw an error
// const invalid = Cron.parseUnsafe("invalid expression")export const const parseUnsafe: (
cron: string,
tz?: DateTime.TimeZone | string
) => Cron
Parses a cron expression into a Cron instance, throwing on failure.
When to use
Use when you expect the input to be valid and want to avoid handling the
Result type.
Example (Parsing cron expressions unsafely)
import { Cron } from "effect"
// At 04:00 on every day-of-month from 8 through 14
const cron = Cron.parseUnsafe("0 0 4 8-14 * *")
// With timezone
const cronWithTz = Cron.parseUnsafe("0 0 9 * * *", "America/New_York")
// This would throw an error
// const invalid = Cron.parseUnsafe("invalid expression")
parseUnsafe = (cron: stringcron: string, tz: DateTime.TimeZone | stringtz?: import DateTimeDateTime.type TimeZone = DateTime.TimeZone.Offset | DateTime.TimeZone.NamedRepresents a time zone used by DateTime.Zoned.
Details
A TimeZone is either a fixed offset from UTC or a named IANA time zone.
Companion namespace containing the public variant and protocol types for
TimeZone.
TimeZone | string): Cron => import ResultResult.const getOrThrow: <A, E>(
self: Result<A, E>
) => A
Extracts the success value or throws the raw failure value E.
When to use
Use when unchecked boundaries should turn failures into thrown exceptions.
Details
Success<A> returns A
Failure<E> throws E directly
- Use
getOrThrowWith
for a custom error object
Example (Unwrapping or throwing)
import { Result } from "effect"
console.log(Result.getOrThrow(Result.succeed(1)))
// Output: 1
// This would throw the string "error":
// Result.getOrThrow(Result.fail("error"))
getOrThrow(const parse: (
cron: string,
tz?: DateTime.TimeZone | string
) => Result.Result<Cron, CronParseError>
Parses a cron expression safely into a Cron instance, returning a Result
instead of throwing.
When to use
Use to parse cron expressions from configuration or user input while handling
invalid input as a Result.
Details
The expression may contain five fields, where seconds default to 0, or six
fields including seconds. Fields support *, comma-separated values, ranges,
steps, and month or weekday aliases. Invalid expressions fail with
CronParseError.
Example (Parsing cron expressions)
import { Cron, Result } from "effect"
import * as assert from "node:assert"
// At 04:00 on every day-of-month from 8 through 14.
assert.deepStrictEqual(
Cron.parse("0 0 4 8-14 * *"),
Result.succeed(Cron.make({
seconds: [0],
minutes: [0],
hours: [4],
days: [8, 9, 10, 11, 12, 13, 14],
months: [],
weekdays: []
}))
)
parse(cron: stringcron, tz: DateTime.TimeZone | stringtz))