public class SchedulerClock
extends java.time.Clock
Scheduler
. That adoption gives better integration with
Java 8 DateTime API.
This feature may be useful for testing purpose, especially for integration with VirtualTimeScheduler
. For example:
VirtualTimeScheduler scheduler = VirtualTimeScheduler.create();
SchedulerClock clock = SchedulerClock.of(scheduler);
ZonedDateTime beforeAdvance = ZonedDateTime.now(clock);
scheduler.advanceTimeBy(Duration.ofSeconds(1));
ZonedDateTime afterAdvance = ZonedDateTime.now(clock);
Assert.assertTrue(beforeAdvance.isBefore(afterAdvance));
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
Scheduler |
getScheduler()
Return wrapped Scheduler instance
|
java.time.ZoneId |
getZone() |
int |
hashCode() |
java.time.Instant |
instant()
Gets the current instant of the clock.
|
long |
millis() |
static SchedulerClock |
of(Scheduler scheduler)
|
static SchedulerClock |
of(Scheduler scheduler,
java.time.ZoneId zoneId)
|
String |
toString() |
SchedulerClock |
withScheduler(Scheduler scheduler)
Builder method that returns new instance of
SchedulerClock which is
constructed from old ZoneId and passed Scheduler instance |
SchedulerClock |
withZone(java.time.ZoneId zone) |
@NonNull public java.time.ZoneId getZone()
getZone
in class java.time.Clock
@NonNull public SchedulerClock withZone(java.time.ZoneId zone)
withZone
in class java.time.Clock
@NonNull public Scheduler getScheduler()
Scheduler
instance@NonNull public SchedulerClock withScheduler(Scheduler scheduler)
SchedulerClock
which is
constructed from old ZoneId
and passed Scheduler
instanceSchedulerClock
instancepublic long millis()
millis
in class java.time.Clock
@NonNull public java.time.Instant instant()
This returns an instant representing the current instant as defined by the clock.
Note: If scheduler does not support time in nanoseconds the returned Instant
will be limited by milliseconds
instant
in class java.time.Clock
public boolean equals(Object o)
equals
in class java.time.Clock
public int hashCode()
hashCode
in class java.time.Clock
@NonNull public static SchedulerClock of(@NonNull Scheduler scheduler)
scheduler
- Scheduler
instanceSchedulerClock
@NonNull public static SchedulerClock of(@NonNull Scheduler scheduler, @NonNull java.time.ZoneId zoneId)
scheduler
- Scheduler
instanceSchedulerClock