Interface TimeService
- All Known Implementing Classes:
DefaultTimeService,MockTimeService
public interface TimeService
This TimeService must be used to lookup the current time in the current session. This service must be used instead of
creating new Date instances or calling the System.currentTimeMillis() directly. The time returned by getCurrentTime()
will not be equal to the current system time when the session context is being used to preview another time.
The current time can be adjusted to any fixed offset from the current system time. This means that the current time always advances at the normal rate. The setTimeOffset(long) and getTimeOffset() methods can be used to modify and query the current offset from system time.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the adjusted current time relative to the time set bysetCurrentTime(Date)with time part normalized to 0.Returns the adjusted current time relative to the time set bysetCurrentTime(Date).longReturns the time offset in milliseconds, which is the time difference between the system time whensetCurrentTime(Date)is called and the argument passed to thesetCurrentTime(Date)voidReset the time back to system time.voidsetCurrentTime(Date instant) Set the current time to the specified time instant.voidsetTimeOffset(long timeOffsetMillis) Set the time offset in milliseconds.
-
Method Details
-
setCurrentTime
Set the current time to the specified time instant. -
getCurrentTime
Date getCurrentTime()Returns the adjusted current time relative to the time set bysetCurrentTime(Date). IfsetCurrentTime(Date)was never called earlier, then current system time is returned. -
getCurrentDateWithTimeNormalized
Date getCurrentDateWithTimeNormalized()Returns the adjusted current time relative to the time set bysetCurrentTime(Date)with time part normalized to 0. IfsetCurrentTime(Date)was never called earlier, then current system time is returned. -
getTimeOffset
long getTimeOffset()Returns the time offset in milliseconds, which is the time difference between the system time whensetCurrentTime(Date)is called and the argument passed to thesetCurrentTime(Date) -
resetTimeOffset
void resetTimeOffset()Reset the time back to system time. CallinggetTimeOffset()after calling this method will get a value of 0. This is equivalent to callingsetTimeOffset(long)with a zero value argument. -
setTimeOffset
void setTimeOffset(long timeOffsetMillis) Set the time offset in milliseconds. Subsequent call togetCurrentTime()will return the system time plus the offset.- Parameters:
timeOffsetMillis- time offset in milliseconds. Use a negative value to adjust time backwards.
-