diff --git a/src/Common/src/CoreLib/System/TimeSpan.cs b/src/Common/src/CoreLib/System/TimeSpan.cs index 2f5c4ed61c19..be5654ef7bb5 100644 --- a/src/Common/src/CoreLib/System/TimeSpan.cs +++ b/src/Common/src/CoreLib/System/TimeSpan.cs @@ -196,7 +196,7 @@ public int CompareTo(TimeSpan value) public static TimeSpan FromDays(double value) { - return Interval(value, MillisPerDay); + return Interval(value, TicksPerDay); } public TimeSpan Duration() @@ -232,28 +232,27 @@ public override int GetHashCode() public static TimeSpan FromHours(double value) { - return Interval(value, MillisPerHour); + return Interval(value, TicksPerHour); } - private static TimeSpan Interval(double value, int scale) + private static TimeSpan Interval(double value, double scale) { if (double.IsNaN(value)) throw new ArgumentException(SR.Arg_CannotBeNaN); - double tmp = value * scale; - double millis = tmp + (value >= 0 ? 0.5 : -0.5); - if ((millis > long.MaxValue / TicksPerMillisecond) || (millis < long.MinValue / TicksPerMillisecond)) + double millis = value * scale; + if ((millis > long.MaxValue) || (millis < long.MinValue)) throw new OverflowException(SR.Overflow_TimeSpanTooLong); - return new TimeSpan((long)millis * TicksPerMillisecond); + return new TimeSpan((long)millis); } public static TimeSpan FromMilliseconds(double value) { - return Interval(value, 1); + return Interval(value, TicksPerMillisecond); } public static TimeSpan FromMinutes(double value) { - return Interval(value, MillisPerMinute); + return Interval(value, TicksPerMinute); } public TimeSpan Negate() @@ -265,7 +264,7 @@ public TimeSpan Negate() public static TimeSpan FromSeconds(double value) { - return Interval(value, MillisPerSecond); + return Interval(value, TicksPerSecond); } public TimeSpan Subtract(TimeSpan ts)