
com.github.markusbernhardt.selenium2library.utils.TimestrHelper Maven / Gradle / Ivy
package com.github.markusbernhardt.selenium2library.utils;
import java.util.ArrayList;
import java.util.List;
public class TimestrHelper {
private boolean compact;
private List ret = new ArrayList();
private String sign;
private int millis;
private int secs;
private int mins;
private int hours;
private int days;
public TimestrHelper(double double_secs) {
this(double_secs, false);
}
public TimestrHelper(double double_secs, boolean compact) {
this.compact = compact;
secsToComponents(double_secs);
addItem(days, "d", "day");
addItem(hours, "h", "hour");
addItem(mins, "min", "minute");
addItem(secs, "s", "second");
addItem(millis, "ms", "millisecond");
}
public String getValue() {
if (ret.size() > 0) {
return sign + Python.join(" ", ret);
}
return compact ? "0s" : "0 seconds";
}
protected int doubleSecsToSecs(double double_secs) {
return (int) double_secs;
}
protected int doubleSecsToMillis(double double_secs) {
int int_secs = doubleSecsToSecs(double_secs);
return (int) Math.round((double_secs - int_secs) * 1000);
}
protected void addItem(int value, String compactSuffix, String longSuffix) {
if (value == 0) {
return;
}
String suffix = compactSuffix;
if (!compact) {
suffix = String.format(" %s%s", longSuffix, pluralOrNot(value));
}
ret.add(String.format("%d%s", value, suffix));
}
protected void secsToComponents(double double_secs) {
if (double_secs < 0) {
sign = "- ";
double_secs = Math.abs(double_secs);
} else {
sign = "";
}
int int_secs = doubleSecsToSecs(double_secs);
millis = doubleSecsToMillis(double_secs);
secs = int_secs % 60;
mins = int_secs / 60 % 60;
hours = int_secs / (60 * 60) % 24;
days = int_secs / (60 * 60 * 24);
}
protected String pluralOrNot(int value) {
return value == 1 ? "" : "s";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy