TimeWindow
Keywords: net.corda.core.contracts.TimeWindow class
Date: 2023-09-18

net.corda.core.contracts

## Class TimeWindow

- net.corda.core.contracts.TimeWindow

-     public class TimeWindow

  An interval on the time-line; not a single instantaneous point.

  There is no such thing as exact time in networked systems due to the underlying physics involved and other issues such as network latency. The best that can be approximated is "fuzzy time" or an instant of time which has margin of tolerance around it. This is what `class TimeWindow` represents. Time windows can be open-ended (i.e. specify only one of `fromTime` and `untilTime`) or they can be fully bounded.

  `class WireTransaction` has an optional time-window property, which if specified, restricts the validity of the transaction to that time-interval as the Consensus Service will not sign it if it's received outside of this window.

  See Also:
    `class TimeWindow`, `fromTime`, `untilTime`, `class WireTransaction`

- - ### Field Detail

    - #### Companion

          public static net.corda.core.contracts.TimeWindow.Companion Companion

  - ### Constructor Detail

    - #### TimeWindow

          public TimeWindow()

      An interval on the time-line; not a single instantaneous point.

      There is no such thing as exact time in networked systems due to the underlying physics involved and other issues such as network latency. The best that can be approximated is "fuzzy time" or an instant of time which has margin of tolerance around it. This is what `class TimeWindow` represents. Time windows can be open-ended (i.e. specify only one of `fromTime` and `untilTime`) or they can be fully bounded.

      `class WireTransaction` has an optional time-window property, which if specified, restricts the validity of the transaction to that time-interval as the Consensus Service will not sign it if it's received outside of this window.

      See Also:
        `class TimeWindow`, `fromTime`, `untilTime`, `class WireTransaction`

  - ### Method Detail

    - #### getFromTime

          @Nullable
          public java.time.Instant getFromTime()

      Returns the inclusive lower-bound of this `class TimeWindow`'s interval, with null implying infinity.

      See Also:
        `class TimeWindow`

    - #### getUntilTime

          @Nullable
          public java.time.Instant getUntilTime()

      Returns the exclusive upper-bound of this `class TimeWindow`'s interval, with null implying infinity.

      See Also:
        `class TimeWindow`

    - #### getMidpoint

          @Nullable
          public java.time.Instant getMidpoint()

      Returns the midpoint of `fromTime` and `untilTime` if both are non-null, calculated as `fromTime + (untilTime - fromTime) / 2`, otherwise returns null.

      See Also:
        `fromTime`, `untilTime`

    - #### getLength

          @Nullable
          public java.time.Duration getLength()

      Returns the duration between `fromTime` and `untilTime` if both are non-null. Otherwise returns null.

      See Also:
        `fromTime`, `untilTime`

    - #### contains

          public boolean contains(@NotNull
                                  java.time.Instant instant)

      Returns true iff the given `instant` is within the time interval of this `class TimeWindow`.

      See Also:
        `instant`, `class TimeWindow`

    - #### fromOnly

          @JvmStatic
           @NotNull
          public static TimeWindow fromOnly(@NotNull
                                                                 java.time.Instant fromTime)

      Creates a `class TimeWindow` with null `untilTime`, i.e. the time interval `[fromTime, ∞)`. `midpoint` will return null.

      See Also:
        `class TimeWindow`, `untilTime`, `midpoint`

    - #### untilOnly

          @JvmStatic
           @NotNull
          public static TimeWindow untilOnly(@NotNull
                                                                  java.time.Instant untilTime)

      Creates a `class TimeWindow` with null `fromTime`, i.e. the time interval `(∞, untilTime)`. `midpoint` will return null.

      See Also:
        `class TimeWindow`, `fromTime`, `midpoint`

    - #### between

          @JvmStatic
           @NotNull
          public static TimeWindow between(@NotNull
                                                                java.time.Instant fromTime,
                                                                @NotNull
                                                                java.time.Instant untilTime)

      Creates a `class TimeWindow` with the time interval `[fromTime, untilTime)`. `midpoint` will return `fromTime + (untilTime - fromTime) / 2`.

      Throws:
        `IllegalArgumentException` - If `fromTime` ≥ `untilTime`
      See Also:
        `class TimeWindow`, `midpoint`

    - #### fromStartAndDuration

          @JvmStatic
           @NotNull
          public static TimeWindow fromStartAndDuration(@NotNull
                                                                             java.time.Instant fromTime,
                                                                             @NotNull
                                                                             java.time.Duration duration)

      Creates a `class TimeWindow` with the time interval `[fromTime, fromTime + duration)`. `midpoint` will return `fromTime + duration / 2`

      See Also:
        `class TimeWindow`, `midpoint`

    - #### withTolerance

          @JvmStatic
           @NotNull
          public static TimeWindow withTolerance(@NotNull
                                                                      java.time.Instant instant,
                                                                      @NotNull
                                                                      java.time.Duration tolerance)

      Creates a `class TimeWindow` which is centered around `instant` with the given `tolerance` on both sides, i.e the time interval `[instant - tolerance, instant + tolerance)`. `midpoint` will return `instant`.

      See Also:
        `class TimeWindow`, `instant`, `tolerance`, `midpoint`, `instant`