[PlutoLib] Cleanup in MiniTime.java

This commit is contained in:
Tefek 2021-01-05 00:14:33 +01:00
parent af3b308adc
commit f61c47b294
2 changed files with 7 additions and 8 deletions

View File

@ -20,6 +20,7 @@
* Added support for version objects * Added support for version objects
* As a result, all fields except the version string are no longer compile-time constants * As a result, all fields except the version string are no longer compile-time constants
* `[PlutoCore]` Made `PlutoApplication`'s constructor private * `[PlutoCore]` Made `PlutoApplication`'s constructor private
* `[PlutoLib]` `MiniTimeParseException` no longer contains a hardcoded String message
Awaiting implementation: Awaiting implementation:
* `[PlutoLib]` Moved `cz.tefek.pluto.io.pluto.pp` to `cz.tefek.pluto.io.plutopackage` * `[PlutoLib]` Moved `cz.tefek.pluto.io.pluto.pp` to `cz.tefek.pluto.io.plutopackage`

View File

@ -47,12 +47,10 @@ public class MiniTime
{ {
public MiniTimeParseException() public MiniTimeParseException()
{ {
super("Time period could not be parsed. Correct format: \\_w\\_d\\_h\\_m\\_s **without spaces** between the units. You can skip a time unit. Example: 1h15m");
} }
} }
private static final TimeUnit miliseconds = TimeUnit.MILLISECONDS;
private static final int DAYS_IN_WEEK = 7; private static final int DAYS_IN_WEEK = 7;
private static final int HOURS_IN_DAY = 24; private static final int HOURS_IN_DAY = 24;
private static final int MINUTES_IN_HOUR = 60; private static final int MINUTES_IN_HOUR = 60;
@ -264,17 +262,17 @@ public class MiniTime
throw new IllegalArgumentException("Negative time span cannot be converted to MiniTime."); throw new IllegalArgumentException("Negative time span cannot be converted to MiniTime.");
} }
var xweeks = miliseconds.toDays(diff) / DAYS_IN_WEEK; var xweeks = TimeUnit.MILLISECONDS.toDays(diff) / DAYS_IN_WEEK;
if (xweeks > Integer.MAX_VALUE) if (xweeks > Integer.MAX_VALUE)
{ {
return "forever"; return "forever";
} }
var xdays = miliseconds.toDays(diff) % DAYS_IN_WEEK; var xdays = TimeUnit.MILLISECONDS.toDays(diff) % DAYS_IN_WEEK;
var xhours = miliseconds.toHours(diff) % HOURS_IN_DAY; var xhours = TimeUnit.MILLISECONDS.toHours(diff) % HOURS_IN_DAY;
var xminutes = miliseconds.toMinutes(diff) % MINUTES_IN_HOUR; var xminutes = TimeUnit.MILLISECONDS.toMinutes(diff) % MINUTES_IN_HOUR;
var xseconds = miliseconds.toSeconds(diff) % SECONDS_IN_MINUTE; var xseconds = TimeUnit.MILLISECONDS.toSeconds(diff) % SECONDS_IN_MINUTE;
return formatTime(xweeks, xdays, xhours, xminutes, xseconds); return formatTime(xweeks, xdays, xhours, xminutes, xseconds);
} }