Skip to content

Commit

Permalink
allow Schedule.cron to accept time zone parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
fubhy committed Dec 10, 2024
1 parent f528ae3 commit 3e19565
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/effect/src/Schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type * as Cause from "./Cause.js"
import type * as Chunk from "./Chunk.js"
import type * as Context from "./Context.js"
import type * as Cron from "./Cron.js"
import type * as DateTime from "./DateTime.js"
import type * as Duration from "./Duration.js"
import type * as Effect from "./Effect.js"
import type * as Either from "./Either.js"
Expand Down Expand Up @@ -403,7 +404,10 @@ export const count: Schedule<number> = internal.count
* @since 2.0.0
* @category constructors
*/
export const cron: (expression: string | Cron.Cron) => Schedule<[number, number]> = internal.cron
export const cron: {
(cron: Cron.Cron): Schedule<[number, number]>
(expression: string, tz?: DateTime.TimeZone | string): Schedule<[number, number]>
} = internal.cron

/**
* Cron-like schedule that recurs every specified `day` of month. Won't recur
Expand Down
8 changes: 6 additions & 2 deletions packages/effect/src/internal/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Chunk from "../Chunk.js"
import * as Clock from "../Clock.js"
import * as Context from "../Context.js"
import * as Cron from "../Cron.js"
import type * as DateTime from "../DateTime.js"
import * as Duration from "../Duration.js"
import type * as Effect from "../Effect.js"
import * as Either from "../Either.js"
Expand Down Expand Up @@ -413,8 +414,11 @@ export const mapInputEffect = dual<
)))

/** @internal */
export const cron = (expression: string | Cron.Cron): Schedule.Schedule<[number, number]> => {
const parsed = Cron.isCron(expression) ? Either.right(expression) : Cron.parse(expression)
export const cron: {
(expression: Cron.Cron): Schedule.Schedule<[number, number]>
(expression: string, tz?: DateTime.TimeZone | string): Schedule.Schedule<[number, number]>
} = (expression: string | Cron.Cron, tz?: DateTime.TimeZone | string): Schedule.Schedule<[number, number]> => {
const parsed = Cron.isCron(expression) ? Either.right(expression) : Cron.parse(expression, tz)
return makeWithState<[boolean, [number, number, number]], unknown, [number, number]>(
[true, [Number.MIN_SAFE_INTEGER, 0, 0]],
(now, _, [initial, previous]) => {
Expand Down

0 comments on commit 3e19565

Please sign in to comment.