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 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 by setCurrentTime(Date). If setCurrentTime(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 by setCurrentTime(Date) with time part normalized to 0. If setCurrentTime(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 when setCurrentTime(Date) is called and the argument passed to the setCurrentTime(Date)
      • resetTimeOffset

        void resetTimeOffset()
        Reset the time back to system time. Calling getTimeOffset() after calling this method will get a value of 0. This is equivalent to calling setTimeOffset(long) with a zero value argument.
      • setTimeOffset

        void setTimeOffset​(long timeOffsetMillis)
        Set the time offset in milliseconds. Subsequent call to getCurrentTime() will return the system time plus the offset.
        Parameters:
        timeOffsetMillis - time offset in milliseconds. Use a negative value to adjust time backwards.