Skip to content

Commit

Permalink
support ticks in time unit
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Feb 1, 2025
1 parent 0f29270 commit e7a80d6
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ private static Map<String, String> getSettings(String query) {
String pattern = Optional.ofNullable(settings.get("pattern")).orElse("HH:mm:ss");
String type = Optional.ofNullable(settings.get("type")).orElse("duration");
long time = value.longValue();
TimeUnit unit = Optional.ofNullable(settings.get("unit"))
.map(s -> {
try {
return TimeUnit.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
})
.orElse(TimeUnit.SECONDS);
String unitString = Optional.ofNullable(settings.get("unit")).orElse("seconds");
TimeUnit unit;
if (unitString.equalsIgnoreCase("ticks")) {
unit = TimeUnit.MILLISECONDS;
time *= 50;
} else {
try {
unit = TimeUnit.valueOf(unitString.toUpperCase());
} catch (IllegalArgumentException e) {
return "INVALID_UNIT";
}
}
long millis = unit.toMillis(time);

if (type.equalsIgnoreCase("time")) {
Expand Down

0 comments on commit e7a80d6

Please sign in to comment.