Skip to content

Commit

Permalink
Fix more issues with duration wrapper
Browse files Browse the repository at this point in the history
(whitespace in between units is now optional, amounts are now correctly summed together)

Fixes #814
  • Loading branch information
MaxNeedsSnacks committed Jun 8, 2024
1 parent 738b58c commit 620dc01
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class UtilsJS {
public static MinecraftServer staticServer = null;
public static final ResourceLocation UNKNOWN_ID = new ResourceLocation("unknown", "unknown");
public static final Predicate<Object> ALWAYS_TRUE = o -> true;
public static final Pattern TEMPORAL_AMOUNT_PATTERN = Pattern.compile("(\\d+)\\s*(y|M|d|w|h|m|s|ms|ns|t)\\b");
public static final Pattern TEMPORAL_AMOUNT_PATTERN = Pattern.compile("(\\d+)\\s*(y|M|d|w|h|m|s|ms|ns|t)\\b?");

private static Collection<BlockState> ALL_STATE_CACHE = null;
private static final Map<String, EntitySelector> ENTITY_SELECTOR_CACHE = new HashMap<>();
Expand Down Expand Up @@ -909,13 +909,13 @@ public static TemporalAmount getTemporalAmount(Object o) {

case "ns" -> nanos += (long) amount;
case "ms" -> millis += (long) amount;
case "s" -> millis = (long) (amount * 1000D);
case "m" -> millis = (long) (amount * 60000D);
case "h" -> millis = (long) (amount * 60000D) * 60L;
case "d" -> millis = (long) (amount * 86400L) * 1000L;
case "w" -> millis = (long) (amount * 86400L) * 7000L;
case "M" -> millis = (long) (amount * 31556952D / 12D) * 1000L;
case "y" -> millis = (long) (amount * 31556952D) * 1000L;
case "s" -> millis += (long) (amount * 1000D);
case "m" -> millis += (long) (amount * 60000D);
case "h" -> millis += (long) (amount * 60000D) * 60L;
case "d" -> millis += (long) (amount * 86400L) * 1000L;
case "w" -> millis += (long) (amount * 86400L) * 7000L;
case "M" -> millis += (long) (amount * 31556952D / 12D) * 1000L;
case "y" -> millis += (long) (amount * 31556952D) * 1000L;
default -> throw new IllegalArgumentException("Invalid temporal unit: " + matcher.group(2));
}
}
Expand Down

0 comments on commit 620dc01

Please sign in to comment.