Improve Precision to 10 microseconds in timespan (#24279)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Mon, 29 Apr 2019 20:56:48 +0000 (13:56 -0700)
committerGitHub <noreply@github.com>
Mon, 29 Apr 2019 20:56:48 +0000 (13:56 -0700)
* 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

src/System.Private.CoreLib/shared/System/TimeSpan.cs
tests/CoreFX/CoreFX.issues.json

index 2f5c4ed..be5654e 100644 (file)
@@ -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)
index 0849d71..04224ba 100644 (file)
         }
     },
     {
+        "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": {
         }
     },
     {
-        "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": {