MCPcopy Create free account
hub / github.com/Effect-TS/effect / cron

Function cron

packages/effect/src/Schedule.ts:709–724  ·  view source on GitHub ↗
(expression: string | Cron.Cron, tz?: string | DateTime.TimeZone, options?: {
  readonly onDstOverlap?: Cron.DstOverlapPolicy | undefined
})

Source from the content-addressed store, hash-verified

707 readonly onDstOverlap?: Cron.DstOverlapPolicy | undefined
708 }): Schedule<Duration.Duration, unknown, Cron.CronParseError>
709} = (expression: string | Cron.Cron, tz?: string | DateTime.TimeZone, options?: {
710 readonly onDstOverlap?: Cron.DstOverlapPolicy | undefined
711}) => {
712 const parsed = Cron.isCron(expression) ? Result.succeed(expression) : Cron.parse(expression, tz, options)
713 return fromStep(effect.map(effect.fromResult(parsed), (cron) => (now, _) => {
714 if (now === Number.POSITIVE_INFINITY) {
715 return Cause.done(Duration.zero)
716 }
717 return effect.sync(() => {
718 let next = Cron.next(cron, now).getTime()
719 if (Duration.isZero(Duration.millis(next - now))) next = Cron.next(cron, next).getTime()
720 const duration = Duration.millis(next - now)
721 return [duration, duration]
722 })
723 }))
724}
725
726/**
727 * Returns a schedule that recurs once after the specified duration.

Callers

nothing calls this directly

Calls 8

fromStepFunction · 0.85
getTimeMethod · 0.80
nextMethod · 0.65
succeedMethod · 0.45
parseMethod · 0.45
mapMethod · 0.45
doneMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected