[FEATURE] Added days into Timer

Credits to @parnassian
This commit is contained in:
SCoutinho
2018-01-02 17:32:45 +00:00
parent a51cd95aae
commit 58d9e23094
@@ -1,11 +1,9 @@
package org.parabot.environment.api.utils;
/**
*
* A simple timer class
*
* @author Everel, Parameter
*
*/
public class Timer {
private long start;
@@ -17,7 +15,6 @@ public class Timer {
* @param end
*/
public Timer(long end) {
start = System.currentTimeMillis();
this.end = System.currentTimeMillis() + end;
}
@@ -92,8 +89,8 @@ public class Timer {
/**
* Calculates hourly gains based on given variable
*
* @param gained
* variable
* @param gained variable
*
* @return hourly gains
*/
public int getPerHour(final int gained) {
@@ -101,7 +98,7 @@ public class Timer {
}
/**
* Generates string based on HH:MM:SS
* Generates string based on DD:HH:MM:SS
*
* @return String
*/
@@ -109,9 +106,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 < 10 ? "0" : "").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);