Class TimeUtil

java.lang.Object
de.murmelmeister.murmelapi.utils.TimeUtil

public final class TimeUtil extends Object
Utility class for time-related operations.
  • Constructor Details

    • TimeUtil

      public TimeUtil()
  • Method Details

    • formatTime

      public static long formatTime(String args)
      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

      public static String formatTimeValue(PlayTime playTime, int userId)
      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

      public static String formatTimeValue(long durationInMilliseconds)
      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

      public static String formatScoreboardTime(PlayTime playTime, int userId)
      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.