We had two TimeWindow classes in Corda core, which has caused ambiguity issues for some users. Delete one and merge functionality.

Address PR comment
This commit is contained in:
Matthew Nesbit 2017-06-15 14:16:14 +01:00
parent 28b850ec85
commit 156a9515ad
5 changed files with 9 additions and 17 deletions

View File

@ -436,12 +436,16 @@ class TimeWindow private constructor(
return TimeWindow(fromTime, untilTime)
}
/** Use when we have a start time and a period of validity. */
@JvmStatic
fun fromStartAndDuration(fromTime: Instant, duration: Duration): TimeWindow = between(fromTime, fromTime + duration)
/**
* When we need to create a [TimeWindow] based on a specific time [Instant] and some tolerance in both sides of this instant.
* The result will be the following time-window: ([time] - [tolerance], [time] + [tolerance]).
*/
@JvmStatic
fun withTolerance(time: Instant, tolerance: Duration) = TimeWindow(time - tolerance, time + tolerance)
fun withTolerance(time: Instant, tolerance: Duration) = between(time - tolerance, time + tolerance)
}
/** The midpoint is calculated as fromTime + (untilTime - fromTime)/2. Note that it can only be computed if both sides are set. */

View File

@ -1,12 +0,0 @@
package net.corda.core.utilities
import java.time.Duration
import java.time.Instant
/**
* A class representing a window in time from a particular instant, lasting a specified duration.
*/
data class TimeWindow(val start: Instant, val duration: Duration) {
val end: Instant
get() = start + duration
}

View File

@ -677,7 +677,7 @@ class InterestRateSwap : Contract {
val nextFixingOf = nextFixingOf() ?: return null
// This is perhaps not how we should determine the time point in the business day, but instead expect the schedule to detail some of these aspects
val instant = suggestInterestRateAnnouncementTimeWindow(index = nextFixingOf.name, source = floatingLeg.indexSource, date = nextFixingOf.forDay).start
val instant = suggestInterestRateAnnouncementTimeWindow(index = nextFixingOf.name, source = floatingLeg.indexSource, date = nextFixingOf.forDay).fromTime!!
return ScheduledActivity(flowLogicRefFactory.create(FixingFlow.FixingRoleDecider::class.java, thisStateRef), instant)
}

View File

@ -98,7 +98,7 @@ open class RatesFixFlow(protected val tx: TransactionBuilder,
class FixQueryFlow(val fixOf: FixOf, val oracle: Party) : FlowLogic<Fix>() {
@Suspendable
override fun call(): Fix {
val deadline = suggestInterestRateAnnouncementTimeWindow(fixOf.name, oracle.name.toString(), fixOf.forDay).end
val deadline = suggestInterestRateAnnouncementTimeWindow(fixOf.name, oracle.name.toString(), fixOf.forDay).untilTime!!
// TODO: add deadline to receive
val resp = sendAndReceive<ArrayList<Fix>>(oracle, QueryRequest(listOf(fixOf), deadline))

View File

@ -1,6 +1,6 @@
package net.corda.irs.utilities
import net.corda.core.utilities.TimeWindow
import net.corda.core.contracts.TimeWindow
import java.time.*
/**
@ -16,5 +16,5 @@ fun suggestInterestRateAnnouncementTimeWindow(index: String, source: String, dat
// Here we apply a blanket announcement time of 11:45 London irrespective of source or index
val time = LocalTime.of(11, 45)
val zoneId = ZoneId.of("Europe/London")
return TimeWindow(ZonedDateTime.of(date, time, zoneId).toInstant(), Duration.ofHours(24))
return TimeWindow.fromStartAndDuration(ZonedDateTime.of(date, time, zoneId).toInstant(), Duration.ofHours(24))
}