[ 
https://issues.apache.org/jira/browse/LANG-1236?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15295453#comment-15295453
 ] 

Nick Manley commented on LANG-1236:
-----------------------------------

The reason I didn't add unit tests is because I couldn't find a way to test it 
comprehensively. The start/end times on the StopWatch class are private. As a 
result, I can't create a fake StopWatch with any arbitrary time. So unless the 
unit tests actually put the test to sleep for an hour or longer, I can't really 
write a test to see if the hours, minutes, seconds will display correctly. The 
current unit tests for the StopWatch only sleep for milliseconds at a time.

Do you think it would be appropriate to add a package-private method for 
modifying the start/end time?

> Add StopWatch#getTime with String Format Argument
> -------------------------------------------------
>
>                 Key: LANG-1236
>                 URL: https://issues.apache.org/jira/browse/LANG-1236
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.time.*
>            Reporter: Nick Manley
>            Priority: Minor
>
> Add a version of the StopWatch#getTime method which takes a String to format 
> the time in the desired format.
> {code}
> StopWatch watch= StopWatch.createStarted();
> // sleep for 1 hour, 19 minutes, 45.554 seconds
> try {Thread.sleep(4785554);} catch (final InterruptedException ex) {}
> watch.stop();
> System.out.println(watch.getTime("HH:mm:ss.SSS");
> // prints: 1:19:45.554
> {code}
> I have a patch ready, but I wasn't sure if this kind of thing should be a 
> part of the getTime method or if toString should be overloaded to take a 
> format argument. Either way seems okay to me. I put it on getTime, but if 
> there are disagreements about that, I would be okay with putting it in 
> toString instead.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to