corda / net.corda.core.contracts / TimeWindow

TimeWindow

abstract 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 TimeWindow represents. Time windows can be open-ended (i.e. specify only one of fromTime and untilTime) or they can be fully bounded.

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.

Constructors

<init>

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

TimeWindow()

Properties

fromTime

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

abstract val fromTime: Instant?

length

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

val length: Duration?

midpoint

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

abstract val midpoint: Instant?

untilTime

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

abstract val untilTime: Instant?

Functions

contains

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

abstract operator fun contains(instant: Instant): Boolean

Companion Object Functions

between

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

fun between(fromTime: Instant, untilTime: Instant): TimeWindow

fromOnly

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

fun fromOnly(fromTime: Instant): TimeWindow

fromStartAndDuration

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

fun fromStartAndDuration(fromTime: Instant, duration: Duration): TimeWindow

untilOnly

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

fun untilOnly(untilTime: Instant): TimeWindow

withTolerance

Creates a 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.

fun withTolerance(instant: Instant, tolerance: Duration): TimeWindow