Skip to content

Commit 7d7bb1a

Browse files
author
Hemed Ali
committed
Format date format to string represantation
1 parent 0b09481 commit 7d7bb1a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/java/org/elasticsearch/river/ubb/settings/RiverUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.elasticsearch.river.ubb.settings;
22

3+
import java.text.DecimalFormat;
34
import java.util.regex.Pattern;
45

56
public class RiverUtils {
@@ -86,16 +87,18 @@ public static boolean isNullOrEmpty(CharSequence s) {
8687
public static String getTimeString(long timeInMilliSeconds) {
8788
//Time in seconds
8889
double timeInSeconds = timeInMilliSeconds/1000.0;
90+
//Format to 2 decimal places
91+
DecimalFormat df = new DecimalFormat(".##");
8992
//In minutes
9093
if (timeInSeconds >= 60 && timeInSeconds < 60 * 60) {
91-
return timeInSeconds/60 + " min";
94+
return df.format(timeInSeconds/60 )+ " minutes";
9295
}
9396
//In hours
9497
if (timeInSeconds >= 60 * 60 && timeInSeconds < 24 * 3600) {
95-
return timeInSeconds/3600 + " hr";
98+
return df.format(timeInSeconds/3600) + " hours";
9699
}
97100
//default unit
98-
return timeInSeconds + " s";
101+
return df.format(timeInSeconds) + " seconds";
99102
}
100103

101104

src/test/java/org/elasticsearch/river/ubb/settings/EEASettingsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class EEASettingsTest {
1010
public void getTimeFormatAsString() {
1111
assertEquals("1.0 seconds", RiverUtils.getTimeString(1000));
1212
assertEquals("1.0 minutes", RiverUtils.getTimeString(60*1000));
13+
assertEquals("3.33 seconds", RiverUtils.getTimeString(3333));
1314
}
1415

1516

0 commit comments

Comments
 (0)