Package de.murmelmeister.murmelapi.utils
Class TimeUtil
java.lang.Object
de.murmelmeister.murmelapi.utils.TimeUtil
Utility class for time-related operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatScoreboardTime(PlayTime playTime, int userId) Formats the given play time into a scoreboard time string.static longformatTime(String args) Formats the given time string into a long value representing the time in milliseconds.static StringformatTimeValue(long durationInMilliseconds) Formats a duration in milliseconds into a human-readable string representation.static StringformatTimeValue(PlayTime playTime, int userId) Formats the time value based on the given PlayTime and user ID.
-
Constructor Details
-
TimeUtil
public TimeUtil()
-
-
Method Details
-
formatTime
Formats the given time string into a long value representing the time in milliseconds. The time string should be a number followed by a time unit. The following time units are supported:- "s" for seconds
- "m" for minutes
- "h" for hours
- "d" for days
- "w" for weeks
- "M" for months (approximated to 30 days)
- "y" for years (approximated to 365 days)
If the time string is "-1", it is considered as permanent and the method returns -1. If the time string starts with "-", it is considered as invalid and the method returns -2. If the time string does not end with a valid time unit, the method returns -3.
- Parameters:
args- the time string to format- Returns:
- the formatted time in milliseconds, or -1, -2, -3 for the special cases described above
- Throws:
RuntimeException- if the time string (excluding the last character) cannot be parsed as a long value
-
formatTimeValue
Formats the time value based on the given PlayTime and user ID.- Parameters:
playTime- The PlayTime object to get the time from.userId- The ID of the user.- Returns:
- The formatted time value as a string.
-
formatTimeValue
Formats a duration in milliseconds into a human-readable string representation. The output includes years, days, hours, minutes, and seconds as applicable.- Parameters:
durationInMilliseconds- the time duration to be formatted, in milliseconds- Returns:
- a formatted string representation of the time duration
-
formatScoreboardTime
Formats the given play time into a scoreboard time string.- Parameters:
playTime- The PlayTime object to get the time from.userId- The ID of the user.- Returns:
- The formatted time value as a string representing the time in days, hours, and years.
-