Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.dashbuilder.dataset.client.engine;
import  com.google.gwt.core.client.Duration;
import  org.dashbuilder.dataset.engine.Chronometer;
public final class ClientChronometer implements Chronometer {
    protected Double startTime;
    protected Double stopTime;
    public long start() {
         = null;
         = Duration.currentTimeMillis();
        return .longValue() * 1000000;
    }
    public long stop() {
         = Duration.currentTimeMillis();
        return .longValue() * 1000000;
    }
    public long elapsedTime() {
        long stop =  != null ? .longValue() : System.currentTimeMillis();
        return (stop - .longValue()) * 1000000;
    }
    public String formatElapsedTime(long millis) {
        long milliseconds = millis;
        long seconds = milliseconds / 1000; milliseconds %= 1000;
        long minutes = seconds / 60; seconds %= 60;
        long hours = minutes / 60; minutes %= 60;
        long days = hours / 24; hours %= 24;
        long weeks = days / 7; days %= 7;
        double secondsd = (double) (seconds * 1000 + milliseconds) / 1000;
        StringBuffer buf = new StringBuffer();
        if (weeks > 0) buf.append(weeks).append(" weeks ");
        if (days > 0) buf.append(days).append("d ");
        if (hours > 0) buf.append(hours).append("h ");
        if (minutes > 0) buf.append(minutes).append("m ");
        if (secondsd > 0) buf.append(secondsd).append("s");
        if (buf.length() == 0) return "0s";
        return buf.toString();
    }
New to GrepCode? Check out our FAQ X