Enum Class TimeUnit

java.lang.Object
java.lang.Enum<TimeUnit>
one.tranic.t.base.parse.time.TimeUnit
All Implemented Interfaces:
Serializable, Comparable<TimeUnit>, Constable

public enum TimeUnit extends Enum<TimeUnit>
The TimeUnit enum represents various units of time, each of which can be used to perform time-based calculations on a LocalDateTime object.

Each time unit is associated with a specific string suffix used for identifying units (e.g., "s" for seconds, "m" for minutes), and provides an implementation for modifying the given time by the specified value of the unit.

TimeUnit supports operations such as adding specific amounts of time to a LocalDateTime instance and retrieving a unit from its designated string suffix.

  • Enum Constant Details

    • SECOND

      public static final TimeUnit SECOND
    • MINUTE

      public static final TimeUnit MINUTE
    • HOUR

      public static final TimeUnit HOUR
    • DAY

      public static final TimeUnit DAY
    • MONTH

      public static final TimeUnit MONTH
    • YEAR

      public static final TimeUnit YEAR
  • Method Details

    • values

      public static TimeUnit[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TimeUnit valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • fromSuffix

      public static TimeUnit fromSuffix(String suffix) throws ParseException
      Determines the TimeUnit associated with the specified string suffix.

      The method iterates over all available TimeUnit values, compares their suffixes, and returns the matching unit.

      Parameters:
      suffix - the string representation of the time unit, such as "s" for seconds, "m" for minutes, etc.
      Returns:
      the TimeUnit corresponding to the provided suffix
      Throws:
      ParseException - if the specified suffix does not match any supported time unit
    • getSuffix

      public String getSuffix()
      Retrieves the string suffix associated with the current time unit.
      Returns:
      the suffix string that identifies the time unit (e.g., "s" for seconds, "m" for minutes)
    • addTime

      public abstract LocalDateTime addTime(LocalDateTime now, long value)
      Adds a specified amount of time to a given LocalDateTime object.
      Parameters:
      now - the initial LocalDateTime instance to which the time will be added
      value - the amount of time to add, specified as a long value
      Returns:
      a new LocalDateTime instance with the added time