Skip to content

Add Temporal support to functions that accept Date #8107

Description

@beeequeue

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:

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".

                        // 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 (nodejs/node#57127 (comment), nodejs/node#57128).

Validations

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    Status
    P2 - 2

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions