Merge branch 'development' into cleanup/duplicated-class

This commit is contained in:
Jeroen Ketelaar
2018-01-28 13:31:29 +00:00
committed by GitHub
2 changed files with 48 additions and 5 deletions
@@ -15,11 +15,21 @@ public class Timer {
* @param end
*/
public Timer(long end) {
start = System.currentTimeMillis();
this.end = System.currentTimeMillis() + end;
}
/**
* Timer Constructor
*
* @param end
* @param start
*/
public Timer(long end, long start) {
this.start = start;
this.end = System.currentTimeMillis() + end;
}
/**
* Timer Constructor
*/
@@ -99,7 +109,7 @@ public class Timer {
}
/**
* Generates string based on HH:MM:SS
* Generates string based on DD:HH:MM:SS
*
* @return String
*/
@@ -107,9 +117,16 @@ public class Timer {
public String toString() {
StringBuilder b = new StringBuilder();
long elapsed = getElapsedTime();
int second = (int) (elapsed / 1000 % 60);
int minute = (int) (elapsed / 60000 % 60);
int hour = (int) (elapsed / 3600000 % 60);
int day = (int) (elapsed / 86400000);
elapsed -= day * 86400000;
int hour = (int) (elapsed / 3600000);
elapsed -= hour * 3600000;
int minute = (int) (elapsed / 60000);
elapsed -= minute * 60000;
int second = (int) (elapsed / 1000);
if (day > 0) {
b.append(day).append("d:");
}
b.append(hour < 10 ? "0" : "").append(hour).append(":");
b.append(minute < 10 ? "0" : "").append(minute).append(":");
b.append(second < 10 ? "0" : "").append(second);
+26
View File
@@ -0,0 +1,26 @@
package org.parabot;
import org.junit.Assert;
import org.junit.Test;
import org.parabot.environment.api.utils.Timer;
/**
* @author JKetelaar
*/
public class TimerTest {
@Test
public void test(){
Timer timer1 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60 * 24));
Assert.assertEquals(timer1.toString(), "1d:00:00:00");
Timer timer2 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 5));
Assert.assertEquals(timer2.toString(), "5d:00:00:00");
Timer timer3 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60));
Assert.assertEquals(timer3.toString(), "01:00:00");
Timer timer4 = new Timer(0, System.currentTimeMillis() - (1000 * 60 * 60 * 12));
Assert.assertEquals(timer4.toString(), "12:00:00");
}
}