From: Anirudh Agnihotry Date: Mon, 29 Apr 2019 20:56:48 +0000 (-0700) Subject: Improve Precision to 10 microseconds in timespan (#24279) X-Git-Tag: accepted/tizen/unified/20190813.215958~42^2~380 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6bca031ae0e612c5d9dbe350e435cce9d9d1919a;p=platform%2Fupstream%2Fcoreclr.git Improve Precision to 10 microseconds in timespan (#24279) * Increasing precision properly and leaving the rounding of to casting operator * disabling corefx tests in coreclr and addressing feedback * correcting test project name * Fix json --- diff --git a/src/System.Private.CoreLib/shared/System/TimeSpan.cs b/src/System.Private.CoreLib/shared/System/TimeSpan.cs index 2f5c4ed..be5654e 100644 --- a/src/System.Private.CoreLib/shared/System/TimeSpan.cs +++ b/src/System.Private.CoreLib/shared/System/TimeSpan.cs @@ -196,7 +196,7 @@ namespace System public static TimeSpan FromDays(double value) { - return Interval(value, MillisPerDay); + return Interval(value, TicksPerDay); } public TimeSpan Duration() @@ -232,28 +232,27 @@ namespace System 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 @@ namespace System public static TimeSpan FromSeconds(double value) { - return Interval(value, MillisPerSecond); + return Interval(value, TicksPerSecond); } public TimeSpan Subtract(TimeSpan ts) diff --git a/tests/CoreFX/CoreFX.issues.json b/tests/CoreFX/CoreFX.issues.json index 0849d71..04224ba 100644 --- a/tests/CoreFX/CoreFX.issues.json +++ b/tests/CoreFX/CoreFX.issues.json @@ -1016,6 +1016,116 @@ } }, { + "name": "System.Runtime.Tests", + "enabled": true, + "exclusions": { + "namespaces": null, + "classes": null, + "methods": [ + { + "name": "System.Tests.TimeSpanTests.FromMilliseconds", + "reason": "The test will be enabled after https://github.com/dotnet/corefx/pull/37235" + }, + { + "name": "System.Tests.TimeSpanTests.FromMilliseconds_Invalid", + "reason": "The test will be enabled after https://github.com/dotnet/corefx/pull/37235" + }, + { + "name": "System.Tests.TimeSpanTests.NamedMultiplication", + "reason": "The test will be enabled after https://github.com/dotnet/corefx/pull/37235" + }, + { + "name": "System.Tests.TimeSpanTests.Multiplication", + "reason": "The test will be enabled after https://github.com/dotnet/corefx/pull/37235" + }, + { + "name": "System.Tests.TimeSpanTests.Division", + "reason": "The test will be enabled after https://github.com/dotnet/corefx/pull/37235" + }, + { + "name": "System.Tests.TimeSpanTests.NamedDivision", + "reason": "The test will be enabled after https://github.com/dotnet/corefx/pull/37235" + }, + { + "name": "System.Text.Tests.StringBuilderTests.Equals", + "reason": "Because of a change in StringBuilder, this test is outdated." + }, + { + "name": "System.Tests.DecimalTests.Remainder", + "reason": "https://github.com/dotnet/coreclr/issues/12605" + }, + { + "name": "System.Tests.DecimalTests.Remainder_Invalid", + "reason": "https://github.com/dotnet/coreclr/issues/12605" + }, + { + "name": "System.Tests.DecimalTests+BigIntegerMod.Test", + "reason": "https://github.com/dotnet/coreclr/issues/12605" + }, + { + "name": "System.Tests.DecimalTests.Round_InvalidMidpointRounding_ThrowsArgumentException", + "reason": "outdated" + }, + { + "name": "System.Tests.ArrayTests.Copy", + "reason": "Needs updates for XUnit 2.4" + }, + { + "name": "System.Tests.ArraySegment_Tests.CopyTo_Invalid", + "reason": "Needs parameter name updated to 'destination'." + }, + { + "name": "System.Tests.TimeSpanTests.Parse_Invalid", + "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" + }, + { + "name": "System.Tests.TimeSpanTests.Parse_Span", + "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" + }, + { + "name": "System.Tests.TimeSpanTests.Parse_Span_Invalid", + "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" + }, + { + "name": "System.Tests.TimeSpanTests.Parse", + "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" + }, + { + "name": "System.Tests.SingleTests.Test_ToString", + "reason" : "https://github.com/dotnet/coreclr/pull/22040" + }, + { + "name": "System.Tests.SingleTests.TryFormat", + "reason" : "https://github.com/dotnet/coreclr/pull/22040" + }, + { + "name": "System.Tests.DoubleTests.Test_ToString", + "reason" : "https://github.com/dotnet/coreclr/pull/22040" + }, + { + "name": "System.Tests.DoubleTests.TryFormat", + "reason" : "https://github.com/dotnet/coreclr/pull/22040" + }, + { + "name": "System.Tests.TimeSpanTests.Total_Days_Hours_Minutes_Seconds_Milliseconds", + "reason" : "https://github.com/dotnet/coreclr/pull/22040" + }, + { + "name": "System.Tests.BufferTests.BlockCopy_Invalid", + "reason": "https://github.com/dotnet/coreclr/pull/23636" + }, + { + "name": "System.Tests.VersionTests.Comparisons_NullArgument_ThrowsArgumentNullException", + "reason": "Version was improved to no longer throw from comparison operators" + }, + { + "name" : "System.Tests.ActivatorNetcoreTests.CreateInstanceAssemblyResolve", + "reason" : "Waiting for https://github.com/dotnet/corefx/pull/37080" + } + ] + } + }, + { "name": "System.Runtime.Extensions.Tests", "enabled": true, "exclusions": { @@ -1343,92 +1453,6 @@ } }, { - "name": "System.Runtime.Tests", - "enabled": true, - "exclusions": { - "namespaces": null, - "classes": null, - "methods": [ - { - "name": "System.Text.Tests.StringBuilderTests.Equals", - "reason": "Because of a change in StringBuilder, this test is outdated." - }, - { - "name": "System.Tests.DecimalTests.Remainder", - "reason": "https://github.com/dotnet/coreclr/issues/12605" - }, - { - "name": "System.Tests.DecimalTests.Remainder_Invalid", - "reason": "https://github.com/dotnet/coreclr/issues/12605" - }, - { - "name": "System.Tests.DecimalTests+BigIntegerMod.Test", - "reason": "https://github.com/dotnet/coreclr/issues/12605" - }, - { - "name": "System.Tests.DecimalTests.Round_InvalidMidpointRounding_ThrowsArgumentException", - "reason": "outdated" - }, - { - "name": "System.Tests.ArrayTests.Copy", - "reason": "Needs updates for XUnit 2.4" - }, - { - "name": "System.Tests.ArraySegment_Tests.CopyTo_Invalid", - "reason": "Needs parameter name updated to 'destination'." - }, - { - "name": "System.Tests.TimeSpanTests.Parse_Invalid", - "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" - }, - { - "name": "System.Tests.TimeSpanTests.Parse_Span", - "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" - }, - { - "name": "System.Tests.TimeSpanTests.Parse_Span_Invalid", - "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" - }, - { - "name": "System.Tests.TimeSpanTests.Parse", - "reason": "Temporary disabling till merging the PR https://github.com/dotnet/corefx/pull/34561" - }, - { - "name": "System.Tests.SingleTests.Test_ToString", - "reason" : "https://github.com/dotnet/coreclr/pull/22040" - }, - { - "name": "System.Tests.SingleTests.TryFormat", - "reason" : "https://github.com/dotnet/coreclr/pull/22040" - }, - { - "name": "System.Tests.DoubleTests.Test_ToString", - "reason" : "https://github.com/dotnet/coreclr/pull/22040" - }, - { - "name": "System.Tests.DoubleTests.TryFormat", - "reason" : "https://github.com/dotnet/coreclr/pull/22040" - }, - { - "name": "System.Tests.TimeSpanTests.Total_Days_Hours_Minutes_Seconds_Milliseconds", - "reason" : "https://github.com/dotnet/coreclr/pull/22040" - }, - { - "name": "System.Tests.BufferTests.BlockCopy_Invalid", - "reason": "https://github.com/dotnet/coreclr/pull/23636" - }, - { - "name": "System.Tests.VersionTests.Comparisons_NullArgument_ThrowsArgumentNullException", - "reason": "Version was improved to no longer throw from comparison operators" - }, - { - "name" : "System.Tests.ActivatorNetcoreTests.CreateInstanceAssemblyResolve", - "reason" : "Waiting for https://github.com/dotnet/corefx/pull/37080" - } - ] - } - }, - { "name": "System.Xml.Linq.SDMSample.Tests", "enabled": true, "exclusions": {