1212
1313package scala .concurrent .duration
1414
15- import java .lang .{ Double => JDouble , Long => JLong }
15+ import java .lang .{ Double => JDouble }
16+ import scala .collection .StringParsers
1617
1718object Duration {
1819
@@ -44,7 +45,7 @@ object Duration {
4445 def apply (length : Long , unit : String ): FiniteDuration = new FiniteDuration (length, Duration .timeUnit(unit))
4546
4647 // Double stores 52 bits mantissa, but there is an implied '1' in front, making the limit 2^53
47- private [this ] final val maxPreciseDouble = 9007199254740992d
48+ // private[this] final val maxPreciseDouble = 9007199254740992d // not used after https://github.com/scala/scala/pull/9233
4849
4950 /**
5051 * Parse String into Duration. Format is `"<length><unit>"`, where
@@ -65,9 +66,8 @@ object Duration {
6566 timeUnit get unitName match {
6667 case Some (unit) =>
6768 val valueStr = s1 dropRight unitName.length
68- val valueD = JDouble .parseDouble(valueStr)
69- if (valueD >= - maxPreciseDouble && valueD <= maxPreciseDouble) Duration (valueD, unit)
70- else Duration (JLong .parseLong(valueStr), unit)
69+ StringParsers .parseLong(valueStr).map(Duration (_, unit))
70+ .getOrElse(Duration (JDouble .parseDouble(valueStr), unit))
7171 case _ => throw new NumberFormatException (" format error " + s)
7272 }
7373 }
0 commit comments