Package net.kamkeyke.raccooncore.util
Class TimeUtils
java.lang.Object
net.kamkeyke.raccooncore.util.TimeUtils
Small utility class for time-related calculations and formatting within the Minecraft environment.
This class provides methods to convert game ticks into human-readable strings.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatTicksToDuration(long ticks) Formats a duration given in game ticks into a human-readable string.static longparseDurationToTicks(String duration) Parses a human-readable duration string into game ticks.
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
formatTicksToDuration
Formats a duration given in game ticks into a human-readable string.The format scales dynamically:
- Values over 24h include days (e.g., "1d 2h 30m")
- Values over 1h omit seconds for brevity (e.g., "1h 15m")
- Small values show minutes and seconds (e.g., "2m 30s")
- Parameters:
ticks- The amount of game ticks to format.- Returns:
- A formatted string (e.g., "1h 30m", "45s", "∞" if negative).
-
parseDurationToTicks
Parses a human-readable duration string into game ticks.The parser identifies units regardless of spacing or order:
- Supports days (d), hours (h), minutes (m), and seconds (s)
- Examples: "1d 12h", "30m 10s", "1h30m"
- The order does not matter (e.g., "10s 1m" is valid)
- Parameters:
duration- The human-readable string to be parsed.- Returns:
- The total duration in ticks, or 0 if no valid patterns are found. Returns -1 if the input is "∞" or null.
-