summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorRoland <rk@rkuhn.info>2012-09-12 11:58:23 +0200
committerRoland <rk@rkuhn.info>2012-09-12 11:58:23 +0200
commit300803606ebca352955e945cf468a0c2bfc83b9c (patch)
tree18bdb6df4b15a7d4ab538a0a5e3be4277e475e81 /src/library
parent85fae9e9771f4671d2ab070c9739436e627460e7 (diff)
downloadscala-300803606ebca352955e945cf468a0c2bfc83b9c.tar.gz
scala-300803606ebca352955e945cf468a0c2bfc83b9c.tar.bz2
scala-300803606ebca352955e945cf468a0c2bfc83b9c.zip
restrict Deadline to finite durations (would have to throw otherwise)
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/concurrent/util/Duration.scala19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/library/scala/concurrent/util/Duration.scala b/src/library/scala/concurrent/util/Duration.scala
index d466d2978f..1a4bc1323d 100644
--- a/src/library/scala/concurrent/util/Duration.scala
+++ b/src/library/scala/concurrent/util/Duration.scala
@@ -28,26 +28,26 @@ import language.implicitConversions
* does not take into account changes to the system clock (such as leap
* seconds).
*/
-case class Deadline private (time: Duration) extends Ordered[Deadline] {
+case class Deadline private (time: FiniteDuration) extends Ordered[Deadline] {
/**
* Return a deadline advanced (i.e. moved into the future) by the given duration.
*/
- def +(other: Duration): Deadline = copy(time = time + other)
+ def +(other: FiniteDuration): Deadline = copy(time = time + other)
/**
* Return a deadline moved backwards (i.e. towards the past) by the given duration.
*/
- def -(other: Duration): Deadline = copy(time = time - other)
+ def -(other: FiniteDuration): Deadline = copy(time = time - other)
/**
* Calculate time difference between this and the other deadline, where the result is directed (i.e. may be negative).
*/
- def -(other: Deadline): Duration = time - other.time
+ def -(other: Deadline): FiniteDuration = time - other.time
/**
* Calculate time difference between this duration and now; the result is negative if the deadline has passed.
*
* '''''Note that on some systems this operation is costly because it entails a system call.'''''
* Check `System.nanoTime` for your platform.
*/
- def timeLeft: Duration = this - Deadline.now
+ def timeLeft: FiniteDuration = this - Deadline.now
/**
* Determine whether the deadline still lies in the future at the point where this method is called.
*
@@ -552,10 +552,6 @@ sealed abstract class Duration extends Serializable with Ordered[Duration] {
* Return the larger of this and that duration as determined by the natural ordering.
*/
def max(other: Duration): Duration = if (this > other) this else other
- /**
- * Construct a [[Deadline]] from this duration by adding it to the current instant `Duration.now`.
- */
- def fromNow: Deadline = Deadline.now + this
// Java API
@@ -655,6 +651,11 @@ final class FiniteDuration(val length: Long, val unit: TimeUnit) extends Duratio
def toDays = unit.toDays(length)
def toUnit(u: TimeUnit) = toNanos.toDouble / NANOSECONDS.convert(1, u)
+ /**
+ * Construct a [[Deadline]] from this duration by adding it to the current instant `Deadline.now`.
+ */
+ def fromNow: Deadline = Deadline.now + this
+
private[this] def unitString = timeUnitName(unit) + ( if (length == 1) "" else "s" )
override def toString = "" + length + " " + unitString