Details
Description
ssue:
The parseDuration(String) method does not respect the decimal place when converting the string representation of milliseconds into an integer/short.
In cases where milliseconds are less than 100, the milliseconds are reported wrong.
Eg.
"0.001" milliseconds is wrongly reported as 100 milliseconds when getMilli() is called after parseDuration(String) "0.01" milliseconds is wrongly reported as 100 milliseconds when getMilli() is called after parseDuration(String) "1.001" milliseconds is wrongly reported as 1.1 seconds when getMilli() is called after parseDuration(String) "1.01" milliseconds is wrongly reported as 1.1 seconds when getMilli() is called after parseDuration(String)
Root Cause:
When the milliseconds are converted from a string to integer, the leading zero's after the decimal place are dropped.
Solution:
Prefix the string representation with a "1" prior to converting to integer and then drop the "1" prior to setting the milliseconds numeric value.
Recommendations:
This class should be refactored to perhaps use a float value to handle intermediate millisecond logic.
The setMilli() method does not need to accept a long as the max value should be 999. I think there is some confusion between get/setMilli and toLong() which is obvious by studing the code. An exception should be thrown if setMilli is supplied with anything > 999. Otherwise, additional logic needs to be added to ensure Y,D,H,M,S are updated accordingly also.
Shawn, can you please supply us with a 'unified diff' against SVN trunk ? Let us know if you need any help with this ....