]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.simulation/src/org/simantics/simulation/experiment/SimulationTimeUtil.java
Added Set End Time command and handler as an alternate stepping mode
[simantics/platform.git] / bundles / org.simantics.simulation / src / org / simantics / simulation / experiment / SimulationTimeUtil.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.simulation.experiment;
13
14 import java.math.RoundingMode;
15 import java.text.NumberFormat;
16 import java.util.Locale;
17
18 import org.simantics.utils.format.TimeFormat;
19
20 /**
21  * @author Tuukka Lehtonen
22  */
23 public class SimulationTimeUtil {
24
25     private static final NumberFormat secondFormatter;
26     private static final TimeFormat timeFormat;
27
28     static {
29         secondFormatter = NumberFormat.getNumberInstance(Locale.US);
30         secondFormatter.setMinimumFractionDigits(2);
31         secondFormatter.setMaximumFractionDigits(3);
32         secondFormatter.setRoundingMode(RoundingMode.HALF_EVEN);
33
34         timeFormat = new TimeFormat(Double.MAX_VALUE, 3);
35     }
36
37     public static String formatSeconds(double time) {
38         return secondFormatter.format(time);
39     }
40
41     /**
42      * Formats a time specified as a double value in seconds in format
43      * <code>[Y]y [D]d hh:mm:ss.SSS</code>
44      * 
45      * @param time
46      * @return
47      */
48     public static String formatHMSS(double time) {
49         String result = timeFormat.format(time);
50 //      System.out.println("formatHMSS(" + time + "): " + result);
51         return result;
52     }
53
54     public static TimeFormat getTimeFormat() {
55         return timeFormat;
56     }
57
58 }