Skip to content

feat: support Temporal.Instant and Temporal.ZonedDateTime in vi.setSystemTime() - #11321

Merged
sheremet-va merged 14 commits into
vitest-dev:mainfrom
Prajwal2246:feat/set-system-time-temporal
Oct 19, 2026
Merged

sheremet-va merged 14 commits into
vitest-dev:mainfrom
Prajwal2246:feat/set-system-time-temporal

Conversation

@Prajwal2246

@Prajwal2246 Prajwal2246 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Updated description by @hi-ogawa

This PR adds support for setSystemTime(Temporal.Instant | Temporal.ZonedDateTime) by following Sinon’s structural type TemporalTimelike = { epochMilliseconds: number } shape to avoid requiring built-in Temporal types. The documented use cases are still only Instant and ZonedDateTime. vi.useFakeTimers({ now }) already supported them through Sinon, so this PR adds tests and documents that existing behavior.


Original description

vi.setSystemTime() throws for a Temporal.Instant because new Date(now) invokes Temporal's throwing valueOf.

This PR accepts Temporal.Instant and Temporal.ZonedDateTime in vi.setSystemTime() and vi.useFakeTimers({ now }) (ref #8107). setSystemTime() converts them with epochMilliseconds; fake-timers already accepts them for now.

The public types resolve Temporal constructors from globalThis and fall back to never when Temporal types are absent. A ZonedDateTime sets the instant, not the system time zone.

Checks

  • Temporal tests: 15 passed across threads, forks, and vmThreads.
  • Adjacent date and mocked-time tests: 15 passed across the same pools.
  • Changed files pass ESLint; packages/vitest builds.
  • Package typecheck still reports three CDPSession.send errors in the untouched src/node/pools/browser.ts.

Disclosure per CONTRIBUTING.md: Claude assisted with the original change, and Codex assisted with this update.

@netlify

netlify Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a333c3f
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6aba3ec18e55090008306df3
😎 Deploy Preview https://deploy-preview-11321--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@Prajwal2246 Prajwal2246 changed the title feat: support Temporal.Instant in vi.setSystemTime feat: support Temporal in fake timers Sep 24, 2026
@Prajwal2246
Prajwal2246 marked this pull request as ready for review September 24, 2026 06:09
@Prajwal2246

Copy link
Copy Markdown
Contributor Author

The two failing e2e jobs don't look related to this change. The same test/mocking.test.ts virtual-module tests are also failing on main:

The macOS --inspect-brk stops at test file failure is a 5s timeout, which also looks flaky. Could someone re-run the failed jobs when you have a moment? Thanks!

@hi-ogawa hi-ogawa changed the title feat: support Temporal in fake timers feat: support Temporal in setSystemTime() Sep 28, 2026
@hi-ogawa hi-ogawa changed the title feat: support Temporal in setSystemTime() feat: support Temporal.Instant and Temporal.ZonedDateTime in setSystemTime() Sep 28, 2026
hi-ogawa
hi-ogawa previously approved these changes Sep 28, 2026
@hi-ogawa hi-ogawa added this to the 5.1.0 milestone Sep 28, 2026
@hi-ogawa hi-ogawa changed the title feat: support Temporal.Instant and Temporal.ZonedDateTime in setSystemTime() feat: support Temporal.Instant and Temporal.ZonedDateTime in vi.setSystemTime() Sep 28, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Hello @Prajwal2246. Thank you for taking the time to contribute!

Unfortunately, the team accepts pull requests only from maintainers and approved contributors, so this pull request was closed automatically. We are sorry about that, it is not a judgement of your work. The number of pull requests grew beyond what the team can review, and this policy gives maintainers the space to triage and prioritize issues at their own pace.

Please keep the discussion in #8107. Your changes are not lost: a maintainer can reopen this pull request if the team decides to go forward with it. See our pull request policy for more context.

@github-actions github-actions Bot closed this Oct 5, 2026
@sheremet-va sheremet-va reopened this Oct 5, 2026
@Prajwal2246

Copy link
Copy Markdown
Contributor Author

Hi @hi-ogawa, the latest CI run is green. Could you take another look when you have a chance? Thanks!

@sheremet-va
sheremet-va merged commit f150f51 into vitest-dev:main Oct 19, 2026
27 of 29 checks passed
@Prajwal2246
Prajwal2246 deleted the feat/set-system-time-temporal branch October 23, 2026 07:06
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Temporal support to functions that accept Date

3 participants