public class SchedulerClock extends 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
|
ZoneId |
getZone() |
int |
hashCode() |
Instant |
instant()
Gets the current instant of the clock.
|
long |
millis() |
static SchedulerClock |
of(Scheduler scheduler)
|
static SchedulerClock |
of(Scheduler scheduler,
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(ZoneId zone) |
fixed, offset, system, systemDefaultZone, systemUTC, tick, tickMinutes, tickSeconds
@NonNull public SchedulerClock withZone(ZoneId zone)
@NonNull public Scheduler getScheduler()
Scheduler
instance@NonNull public SchedulerClock withScheduler(Scheduler scheduler)
SchedulerClock
which is
constructed from old ZoneId
and passed Scheduler
instanceSchedulerClock
instance@NonNull public 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
@NonNull public static SchedulerClock of(@NonNull Scheduler scheduler)
scheduler
- Scheduler
instanceSchedulerClock
@NonNull public static SchedulerClock of(@NonNull Scheduler scheduler, @NonNull ZoneId zoneId)
scheduler
- Scheduler
instanceSchedulerClock