Skip to content

Commit

Permalink
currentTime
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrolienF committed Aug 21, 2024
1 parent 1ae1065 commit bb69470
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/fr/formiko/utils/FLUTime.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fr.formiko.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
* {@summary Time functions.}<br>
*
Expand All @@ -19,8 +22,8 @@ public static String msToTime(long ms, int nbrOfUnit, boolean dayOn) {
if (nbrOfUnit < 1) {
return "";
}
String ts[] = {"t.d", "t.h", "t.min", "t.s", "t.ms"};
long tl[] = msToTimeLongArray(ms, dayOn);
String[] ts = {"t.d", "t.h", "t.min", "t.s", "t.ms"};
long[] tl = msToTimeLongArray(ms, dayOn);
int k = 0;
int i = 0;
String r = "";
Expand Down Expand Up @@ -61,7 +64,7 @@ public static String msToTime(long ms, int nbrOfUnit, boolean dayOn) {
* @param dayOn enable or disable day as a unit.
*/
public static long[] msToTimeLongArray(long ms, boolean dayOn) {
long tr[] = new long[5];
long[] tr = new long[5];
if (ms < 0) {
tr[4] = -1;
return tr;
Expand Down Expand Up @@ -101,7 +104,15 @@ public static void sleep(int ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException ie) {
return;
// return;
}
}

/**
* {@summary return the current time as a String 2019-12-31 23-59-59.999}
*/
public static String currentTime() {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss.SSS");
return df.format(System.currentTimeMillis());
}
}
17 changes: 17 additions & 0 deletions src/test/java/fr/formiko/utils/FLUTimeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.formiko.utils;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

class FLUTimeTest {
@Test
void testCurrentTime() {
// assertEquals(expected, FLUStrings.addAtTheEndIfNeeded(string, toAdd));
String result = FLUTime.currentTime();
assertEquals(23, result.length());
// Test that the result have only number, ' ', '-' and '.'
assertTrue(result.matches("[0-9\\-\\s\\.]{" + result.length() + "}"));
}

}

0 comments on commit bb69470

Please sign in to comment.