Skip to content

Conversation

@tmcw
Copy link

@tmcw tmcw commented Oct 31, 2025

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Okay, so this is timezone-related, so it's kind of confusing. I think the gist is: the root cause of is that when you do Cron.sequence with implicit timezones, you get into a situation in which,

  1. The cron occurs every week, and it hops from one Monday at 1pm to the next Monday at 1pm, and records that as the next tick
  2. But, daylight savings has happened so the cron should happen at 2pm instead of 1pm, so it jumps forward to 2pm and records that as the next tick

Which is how you get odd consecutive cron executions around time zones.

This PR makes 'implicit' timezones explicit internally using Intl.DateTimeFormat().resolvedOptions().timeZone. Is this good and the "right way to do it"? I'm not sure - this is pretty tricky stuff! But it does make crons consistent and a cron that should fire once a week does fire once a week reliably with this method.

Related

@tmcw tmcw requested a review from mikearnaldi as a code owner October 31, 2025 21:08
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Oct 31, 2025
@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2025

🦋 Changeset detected

Latest commit: fe42df8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
effect Patch
@effect/cli Patch
@effect/cluster Patch
@effect/experimental Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/platform Patch
@effect/printer-ansi Patch
@effect/printer Patch
@effect/rpc Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-drizzle Patch
@effect/sql-kysely Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/sql Patch
@effect/typeclass Patch
@effect/vitest Patch
@effect/workflow Patch
@effect/ai Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-google Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tmcw
Copy link
Author

tmcw commented Nov 1, 2025

Hmm, having dug into it more I think the root cause might be that unsafeMakeZoned uses an offset-based timezone if one isn't given, and this doesn't compensate for timezone shifts correctly. I've updated this PR instead to improve that method to use the inferred named zone when one isn't given.

That said, I think that manually supplying an offset-based time zone to the Cron methods will still produce the original bug.

@tmcw tmcw changed the title Always use an explicit timezone for cron sequences Use a named timezone as the default for unsafeMakeZoned Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

Cron appears to repeat a date

1 participant