Skip to content

feat(clock): add java.time.Instant overloads to the Clock API#1937

Closed
yury-s wants to merge 1 commit into
microsoft:mainfrom
yury-s:clock-instant-overloads
Closed

feat(clock): add java.time.Instant overloads to the Clock API#1937
yury-s wants to merge 1 commit into
microsoft:mainfrom
yury-s:clock-instant-overloads

Conversation

@yury-s

@yury-s yury-s commented Jun 19, 2026

Copy link
Copy Markdown
Member

Draft / exploration for #1686.

Summary

  • Adds java.time.Instant overloads to Clock.pauseAt/setFixedTime/setSystemTime and Clock.InstallOptions.setTime, alongside the existing java.util.Date ones.
  • The API generator synthesizes the extra Instant overload for Date-typed unions (which occur only in Clock); ClockImpl's Date/Instant overloads delegate to the canonical millis-based long overload.

Design note

The issue asks for LocalDateTime, but a system/fixed time is an absolute instant and LocalDateTime has no zone — converting it would force a silent systemDefault() guess. So this exposes Instant (the unambiguous match) instead; callers holding a LocalDateTime convert explicitly, e.g. localDateTime.toInstant(ZoneOffset.UTC) (the added test demonstrates this).

References #1686

Add Instant overloads to Clock.pauseAt/setFixedTime/setSystemTime and
InstallOptions.setTime alongside the existing java.util.Date ones. The API
generator synthesizes an Instant overload for Date-typed unions (Clock only);
the Date/Instant impls delegate to the canonical millis-based overload.

References microsoft#1686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant