Added new method toHumanString() to class Duration
This commit is contained in:
parent
abeeb87cbf
commit
8c8fd9b88d
@ -1,4 +1,3 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
@ -17,7 +16,6 @@
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.time.duration;
|
||||
|
||||
import org.nanoboot.powerframework.random.generators.RandomGenerator;
|
||||
@ -427,4 +425,27 @@ public final class Duration {
|
||||
DOT,
|
||||
String.format("%03d", get(TimeUnit.MILLISECOND)));
|
||||
}
|
||||
|
||||
public String toHumanString() {
|
||||
long days = get(TimeUnit.DAY);
|
||||
long hours = get(TimeUnit.HOUR);
|
||||
long minutes = get(TimeUnit.MINUTE);
|
||||
long seconds = get(TimeUnit.SECOND);
|
||||
long milliseconds = get(TimeUnit.MILLISECOND);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!this.isPositive()) {
|
||||
sb.append(MINUS).append(" ");
|
||||
}
|
||||
if (days > 0) {
|
||||
sb.append(days).append(" ").append(TimeUnit.DAY.name().toLowerCase()).append((days > 1) ? "s" : "").append(" ");
|
||||
}
|
||||
if (hours > 0) {
|
||||
sb.append(hours).append(" ").append(TimeUnit.HOUR.name().toLowerCase()).append((hours > 1) ? "s" : "").append(" ");
|
||||
}
|
||||
if (minutes > 0) {
|
||||
sb.append(minutes).append(" ").append(TimeUnit.MINUTE.name().toLowerCase()).append((minutes > 1) ? "s" : "").append(" ");
|
||||
}
|
||||
sb.append(seconds).append(" ").append(TimeUnit.SECOND.name().toLowerCase()).append((seconds > 1) ? "s" : "");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user