TimeSpan.FromMilliseconds Incorrect Parsing - by Kasper Holdum

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


6
0
Sign in
to vote
ID 653782 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 3/27/2011 9:14:03 AM
Access Restriction Public

Description

Note: I'm aware the documentation states that the input value only be considered accurate to the nearest millisecond, but this seems like a bad implementation.

The FromMilliseconds method takes a double, but is not effectively capable of parsing values less than 0.5. This means that anything below 0.5 will be parsed as a total of 0 ticks. 

Since one millisecond is 10000 ticks, this method should be capable of handling numbers as small as 0.0001.
Sign in to post a comment.
Posted by Roman.St on 6/19/2011 at 12:21 AM
I think the voters here realise that it is by design, however the behaviour is counter-productive and entirely unexpected.

Was this a *good* design, in hindsight? I think not.

Can it be changed without breaking anything? That's a tricky one... I'd like this to be at least considered though.
Posted by Microsoft on 4/4/2011 at 10:44 AM
Hello Qua2,
TimeSpan.FromMilliseconds rounds down to the nearest millisecond. Please see http://msdn.microsoft.com/en-us/library/system.timespan.frommilliseconds(v=VS.100).aspx
/*
This example of TimeSpan.FromMilliseconds( double )
generates the following output.

     FromMilliseconds         TimeSpan
     ----------------         --------
                    1         00:00:00.0010000
                 1.5         00:00:00.0020000
             12345.6         00:00:12.3460000
         123456789.8        1.10:17:36.7900000
     1234567898765.4    14288.23:31:38.7650000
                 1000         00:00:01
                60000         00:01:00
             3600000         01:00:00
             86400000        1.00:00:00
         1801220200     20.20:20:20.2000000
*/
Posted by Microsoft on 3/27/2011 at 9:25 PM
Thank you for reporting the issue.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.These specialized experts will follow-up with your issue.
Posted by Microsoft on 3/27/2011 at 10:15 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)