Skip to content

Commit bb69470

Browse files
committed
currentTime
1 parent 1ae1065 commit bb69470

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/main/java/fr/formiko/utils/FLUTime.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package fr.formiko.utils;
22

3+
import java.text.DateFormat;
4+
import java.text.SimpleDateFormat;
5+
36
/**
47
* {@summary Time functions.}<br>
58
*
@@ -19,8 +22,8 @@ public static String msToTime(long ms, int nbrOfUnit, boolean dayOn) {
1922
if (nbrOfUnit < 1) {
2023
return "";
2124
}
22-
String ts[] = {"t.d", "t.h", "t.min", "t.s", "t.ms"};
23-
long tl[] = msToTimeLongArray(ms, dayOn);
25+
String[] ts = {"t.d", "t.h", "t.min", "t.s", "t.ms"};
26+
long[] tl = msToTimeLongArray(ms, dayOn);
2427
int k = 0;
2528
int i = 0;
2629
String r = "";
@@ -61,7 +64,7 @@ public static String msToTime(long ms, int nbrOfUnit, boolean dayOn) {
6164
* @param dayOn enable or disable day as a unit.
6265
*/
6366
public static long[] msToTimeLongArray(long ms, boolean dayOn) {
64-
long tr[] = new long[5];
67+
long[] tr = new long[5];
6568
if (ms < 0) {
6669
tr[4] = -1;
6770
return tr;
@@ -101,7 +104,15 @@ public static void sleep(int ms) {
101104
try {
102105
Thread.sleep(ms);
103106
} catch (InterruptedException ie) {
104-
return;
107+
// return;
105108
}
106109
}
110+
111+
/**
112+
* {@summary return the current time as a String 2019-12-31 23-59-59.999}
113+
*/
114+
public static String currentTime() {
115+
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss.SSS");
116+
return df.format(System.currentTimeMillis());
117+
}
107118
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package fr.formiko.utils;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
import org.junit.jupiter.api.Test;
6+
7+
class FLUTimeTest {
8+
@Test
9+
void testCurrentTime() {
10+
// assertEquals(expected, FLUStrings.addAtTheEndIfNeeded(string, toAdd));
11+
String result = FLUTime.currentTime();
12+
assertEquals(23, result.length());
13+
// Test that the result have only number, ' ', '-' and '.'
14+
assertTrue(result.matches("[0-9\\-\\s\\.]{" + result.length() + "}"));
15+
}
16+
17+
}

0 commit comments

Comments
 (0)