[miniflare] Default workerd subprocess to TZ=UTC to match production#13776
[miniflare] Default workerd subprocess to TZ=UTC to match production#13776petebacondarwin wants to merge 4 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: c7b3cfe The changes in this PR will be included in the next version bump. 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 |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
Changeset ReviewChangesets Reviewed
Validation Results
|
|
I've now reviewed the entire PR carefully. Let me assess the issues:
The code is clean, the logic is correct, and the tests appropriately validate both the default UTC behavior and the override mechanism. The LGTM |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Cloudflare's production runtime runs Workers with TZ=UTC, but Miniflare inherited the host machine's timezone, causing dev/prod drift in `Date` and `Intl` behaviour. Local development now matches production by default, with a new `unsafeRuntimeEnv` option for advanced consumers that need to test timezone-dependent behaviour. Closes #8106
A diagnostic probe on Windows CI proved that workerd-on-Windows always reports `UTC` from `Intl.DateTimeFormat().resolvedOptions().timeZone` regardless of the `TZ` env var passed to its subprocess — every value tried (`America/Chicago`, `Asia/Tokyo`, `Europe/London`, `Etc/GMT+5`, `Etc/UTC`, `UTC`, `PST8PDT`) resolved to `UTC`. This is a workerd limitation on Windows. The user-facing default (`TZ=UTC`) and the override mechanism are unchanged — the override test simply has no observable effect on Windows, so we skip it there.
e39af5a to
c7b3cfe
Compare
Fixes #8106.
Cloudflare's production runtime runs Workers with
TZ=UTC, but Miniflare inherited the host machine's timezone, causing dev/prod drift inDateandIntlbehaviour. Local development now matches production by default.Changes
packages/miniflare/src/runtime/index.ts— when spawning theworkerdsubprocess, defaultTZto"UTC"and merge any caller-provided overrides last. Added aruntimeEnv?: Record<string, string>field toRuntimeOptions.packages/miniflare/src/plugins/core/index.ts— addedunsafeRuntimeEnv: z.record(z.string()).optional()toCoreSharedOptionsSchemaso library consumers can override the default (e.g.{ TZ: "Europe/London" }for testing timezone-dependent behaviour).packages/miniflare/src/index.ts— wired the option through to the runtime.packages/miniflare/README.md— documented the newunsafeRuntimeEnvoption alongside the existingunsafe*shared options.The user-facing behaviour change is that
wrangler dev(and every other Miniflare-backed surface —wrangler kv/d1/r2/check,vitest-pool-workers,vite-plugin-cloudflare, etc.) now run withTZ=UTCby default, matching production. Consumers who genuinely need a different timezone can passunsafeRuntimeEnvdirectly toMiniflare.A picture of a cute animal (not mandatory, but encouraged)