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>

TimeWindow()

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

Properties

fromTime

abstract val fromTime: Instant?

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

length

val length: Duration?

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

midpoint

abstract val midpoint: Instant?

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

untilTime

abstract val untilTime: Instant?

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

Functions

contains

abstract operator fun contains(instant: Instant): Boolean

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

Companion Object Functions

between

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

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

fromOnly

fun fromOnly(fromTime: Instant): TimeWindow

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

fromStartAndDuration

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

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

untilOnly

fun untilOnly(untilTime: Instant): TimeWindow

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

withTolerance

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

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.

Extension Functions

contextLogger

fun Any.contextLogger(): Logger

When called from a companion object, returns the logger for the enclosing class.