#8107·vitest

Add `Temporal` support to functions that accept `Date`

Author: beeequeueCreated Jun 5, 2025Updated Sep 16, 2026
Labelsp2-nice-to-have

Clear and concise description of the problem

I'm testing out using Temporal instead of Date, and one of the pain points I found is vi.setSystemTime only accepting number | Date.

Suggested solution

Add Temporal as an option to functions that accept Date. The one I encountered was vi.setSystemTime

Alternative

As a workaround, you can convert a PlainDate[Time] to a ZonedDateTime or Instant and get the epoch time from that:

typescript
vi.setSystemTime(
  Temporal.PlainDateTime.from("2022-02-02 12:00").toZonedDateTime("utc")
    .epochMilliseconds,
)

Additional context

Some Temporal support was added in #8007 but that could be achieved without having to use the Temporal global, which I think this feature would require.

For example, (I believe) to support PlainDate in vi.setSystemTime one would have to convert it to a ZonedDatetime to get .epochMilliseconds, which might require using Temporal.Now.timeZoneId() unless you would default to "UTC".

javascript
                        // or "UTC"?
plainDate.toZonedDateTime(Temporal.Now.timeZoneId()).epochMilliseconds

To support this one would probably have to use temporal-polyfill in some way until V8 implements Temporal (https://github.com/nodejs/node/issues/57127#issuecomment-2762978399, https://github.com/nodejs/node/pull/57128).

Validations