mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Merge branch 'development' into cleanup/duplicated-class
This commit is contained in:
@@ -15,11 +15,21 @@ public class Timer {
|
|||||||
* @param end
|
* @param end
|
||||||
*/
|
*/
|
||||||
public Timer(long end) {
|
public Timer(long end) {
|
||||||
|
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
this.end = System.currentTimeMillis() + end;
|
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
|
* 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
|
* @return String
|
||||||
*/
|
*/
|
||||||
@@ -107,9 +117,16 @@ public class Timer {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
long elapsed = getElapsedTime();
|
long elapsed = getElapsedTime();
|
||||||
int second = (int) (elapsed / 1000 % 60);
|
int day = (int) (elapsed / 86400000);
|
||||||
int minute = (int) (elapsed / 60000 % 60);
|
elapsed -= day * 86400000;
|
||||||
int hour = (int) (elapsed / 3600000 % 60);
|
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(hour < 10 ? "0" : "").append(hour).append(":");
|
||||||
b.append(minute < 10 ? "0" : "").append(minute).append(":");
|
b.append(minute < 10 ? "0" : "").append(minute).append(":");
|
||||||
b.append(second < 10 ? "0" : "").append(second);
|
b.append(second < 10 ? "0" : "").append(second);
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user