commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [lang] StopWatch enhancement
Date Wed, 12 Mar 2003 00:06:08 GMT

What???

Return should be an int[] as in Unix-C/Perl

[tongue in cheek, honest]

On Tue, 11 Mar 2003, Robert McIntosh wrote:

> 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" <robert@bull-enterprises.com>
> >To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
> >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: commons-dev-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>>
> >>>
> >>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >>
> >>
> >>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message