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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Date
getCurrentDateWithTimeNormalized()
Returns the adjusted current time relative to the time set bysetCurrentTime(Date)
with time part normalized to 0.java.util.Date
getCurrentTime()
Returns the adjusted current time relative to the time set bysetCurrentTime(Date)
.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)
void
resetTimeOffset()
Reset the time back to system time.void
setCurrentTime(java.util.Date instant)
Set the current time to the specified time instant.void
setTimeOffset(long timeOffsetMillis)
Set the time offset in milliseconds.
-
-
-
Method Detail
-
setCurrentTime
void setCurrentTime(java.util.Date instant)
Set the current time to the specified time instant.
-
getCurrentTime
java.util.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
java.util.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.
-
-