From 6c978497a1c16373153c9263a2d1be09949b5b09 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 29 Mar 2017 21:30:23 -0400 Subject: [PATCH] Revert "TimeSpan.FromMilliseconds(TimeSpan.MaxValue.TotalMilliseconds) exception fix (#10352)" (#10552) This reverts commit 7951bc9accbbf9552d9b5c8105df8f5a32d6c3ab. --- src/mscorlib/src/System/TimeSpan.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mscorlib/src/System/TimeSpan.cs b/src/mscorlib/src/System/TimeSpan.cs index 23bc5c4..9166656 100644 --- a/src/mscorlib/src/System/TimeSpan.cs +++ b/src/mscorlib/src/System/TimeSpan.cs @@ -252,10 +252,10 @@ namespace System throw new ArgumentException(SR.Arg_CannotBeNaN); Contract.EndContractBlock(); double tmp = value * scale; - double ticks = Math.Round(tmp * TicksPerMillisecond, 0); - if ((ticks > Int64.MaxValue) || (ticks < Int64.MinValue)) + double millis = tmp + (value >= 0 ? 0.5 : -0.5); + if ((millis > Int64.MaxValue / TicksPerMillisecond) || (millis < Int64.MinValue / TicksPerMillisecond)) throw new OverflowException(SR.Overflow_TimeSpanTooLong); - return new TimeSpan((long)ticks); + return new TimeSpan((long)millis * TicksPerMillisecond); } public static TimeSpan FromMilliseconds(double value) -- 2.7.4