-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.0.6 - New and improved config & kick messages! More customized kic…
…k time.
- Loading branch information
Fido2603
committed
May 26, 2019
1 parent
eb00a0c
commit cb13e5a
Showing
5 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dk.fido2603.semihardcore; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class TimeConverter | ||
{ | ||
// parseStringToMillis() and convert() is from https://stackoverflow.com/a/4015476 | ||
public static long parseStringToMillis(String input) { | ||
long result = 0; | ||
String number = ""; | ||
for (int i = 0; i < input.length(); i++) { | ||
char c = input.charAt(i); | ||
if (Character.isDigit(c)) { | ||
number += c; | ||
} else if (Character.isLetter(c) && !number.isEmpty()) { | ||
result += convert(Integer.parseInt(number), c); | ||
number = ""; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
private static long convert(int value, char unit) { | ||
switch(unit) { | ||
case 'd' : return value * 1000*60*60*24; | ||
case 'h' : return value * 1000*60*60; | ||
case 'm' : return value * 1000*60; | ||
case 's' : return value * 1000; | ||
} | ||
return 0; | ||
} | ||
|
||
// Self-made from here | ||
public static String parseMillisToUFString(long millis) { | ||
long banDays = TimeUnit.MILLISECONDS.toDays(millis); | ||
long banHours = TimeUnit.MILLISECONDS.toHours(millis); | ||
long banMinutes = TimeUnit.MILLISECONDS.toMinutes(millis); | ||
|
||
if (banDays > 0) { | ||
if ((banHours - TimeUnit.DAYS.toHours(banDays)) > 0) { | ||
if ((banMinutes - TimeUnit.HOURS.toMinutes(banHours)) > 0) { | ||
return String.format("%d days, %d hours and %d minutes", banDays, banHours - TimeUnit.DAYS.toHours(banDays), banMinutes - TimeUnit.HOURS.toMinutes(banHours)); | ||
} | ||
return String.format("%d days, %d hours", banDays, banHours - TimeUnit.DAYS.toHours(banDays)); | ||
} | ||
return String.format("%d days", banDays); | ||
} | ||
if (banHours > 0) { | ||
if ((banMinutes - TimeUnit.HOURS.toMinutes(banHours)) > 0) { | ||
return String.format("%d hours and %d minutes", banHours, banMinutes - TimeUnit.HOURS.toMinutes(banHours)); | ||
} | ||
return String.format("%d hours", banHours); | ||
} | ||
return String.format("%d minutes", banMinutes); | ||
} | ||
|
||
} |