Good questions. The returns are strings.

Stephen Colebourne wrote:

The biggest problem with StopWatch and the other time classes is working out
exactly how they should work and inter-relate, particularly re formats
(everybody has their own favorite).

And interestingly, its not entirely obvious to me as to what the getXxx
methods return - is it a string or a number? Whats the format? How is
localization dealt with? ((see also joda.sourceforge.net))

Stephen

----- Original Message -----
From: "Robert McIntosh" <[EMAIL PROTECTED]>
To: "Jakarta Commons Developers List" <[EMAIL PROTECTED]>
Sent: Tuesday, March 11, 2003 7:56 PM
Subject: Re: [lang] StopWatch enhancement




If interested, in my own timer class, I have these extra format/output
options that I wouldn't mind adding to StopWatch:

getMinutesWithMilliSeconds
getMinutesWithSeconds
getMinutes
getSeconds
getSecondsWithMilliSeconds
getMilliSeconds

which should be self explanatory.

- Robert

Robert McIntosh wrote:



I tried out the StopWatch class as pointed out to me by Stephen and I
added an extra toString method for a different format option. The
extra option is:
0hrs 0mins 0secs 0ms.

Add if desired :-)

- Robert

------------------------------------------------------------------------

? stopWatchEnhancement.txt
Index: StopWatch.java
===================================================================
RCS file:


/home/cvspublic/jakarta-commons/lang/src/java/org/apache/commons/lang/time/S
topWatch.java,v


retrieving revision 1.2
diff -u -r1.2 StopWatch.java
--- StopWatch.java 4 Feb 2003 22:19:33 -0000 1.2
+++ StopWatch.java 11 Mar 2003 19:48:06 -0000
@@ -235,5 +235,46 @@
buf.append(milliseconds);
return buf.toString();
}
+
+ /**
+ * <p>Get the time gap as a long formatted string.</p>
+ *
+ * <p>The format used is,
+ * <i>hours</i><b>hrs</b> <i>minutes</i><b>mins</b>


<i>seconds</i><b>secs</b> <i>milliseconds</i><b>ms</b></p>


+     *
+     * @return the time as a String
+     */
+    public static String toStringLongFormat(long time) {
+        int hours, minutes, seconds, milliseconds;
+        hours = (int) (time / MILLIS_IN_HOUR);
+        time = time - (hours * MILLIS_IN_HOUR);
+        minutes = (int) (time / MILLIS_IN_MINUTE);
+        time = time - (minutes * MILLIS_IN_MINUTE);
+        seconds = (int) (time / 1000);
+        time = time - (seconds * 1000);
+        milliseconds = (int) time;
+
+        StringBuffer buf = new StringBuffer(48);
+        buf.append(hours);
+        buf.append("hrs ");
+        if (minutes < 10) {
+            buf.append('0');
+        }
+        buf.append(minutes);
+        buf.append("mins ");
+        if (seconds < 10) {
+            buf.append('0');
+        }
+        buf.append(seconds);
+        buf.append("secs ");
+        if (milliseconds < 10) {
+            buf.append("00");
+        } else if (milliseconds < 100) {
+            buf.append('0');
+        }
+        buf.append(milliseconds);
+        buf.append("ms");
+        return buf.toString();
+    }

}



------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to