Class TimeUtils

java.lang.Object
org.bitcoinj.base.internal.TimeUtils

public class TimeUtils extends Object
Utilities for time and mock time.
  • Constructor Details

    • TimeUtils

      public TimeUtils()
  • Method Details

    • setMockClock

      public static void setMockClock()
      Sets the mock clock to the current time as a fixed instant.
    • setMockClock

      public static void setMockClock(Instant fixedInstant)
      Sets the mock clock to a fixed instant.
      Parameters:
      fixedInstant - a fixed instant
    • rollMockClock

      public static void rollMockClock(Duration delta)
      Rolls an already set mock clock by the given duration.
      Parameters:
      delta - amount to roll the mock clock, can be negative
      Throws:
      IllegalStateException - if the mock clock isn't set
    • clearMockClock

      public static void clearMockClock()
      Clears the mock clock and causes time to tick again.
    • currentTime

      public static Instant currentTime()
      Returns the current time as an Instant, or a mocked out equivalent.
    • elapsedTime

      public static Duration elapsedTime(Instant start)
      Returns elapsed time between given start and current time as a Duration.

      Note that this method is affected by the mock clock. If you want to raise real debug data use Stopwatch.

    • earlier

      public static Instant earlier(Instant time1, Instant time2)
      Determines the earlier of two instants.
    • later

      public static Instant later(Instant time1, Instant time2)
      Determines the later of two instants.
    • longest

      public static Duration longest(Duration duration1, Duration duration2)
      Determines the longest of two durations.
    • dateTimeFormat

      public static String dateTimeFormat(Instant time)
      Formats a given date+time value to an ISO 8601 string.
      Parameters:
      time - date and time to format