Package one.tranic.t.base.parse.time
Enum Class TimeUnit
- All Implemented Interfaces:
Serializable,Comparable<TimeUnit>,Constable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionabstract LocalDateTimeaddTime(LocalDateTime now, long value) Adds a specified amount of time to a givenLocalDateTimeobject.static TimeUnitfromSuffix(String suffix) Determines theTimeUnitassociated with the specified string suffix.Retrieves the string suffix associated with the current time unit.static TimeUnitReturns the enum constant of this class with the specified name.static TimeUnit[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
SECOND
-
MINUTE
-
HOUR
-
DAY
-
MONTH
-
YEAR
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
fromSuffix
Determines theTimeUnitassociated with the specified string suffix.The method iterates over all available
TimeUnitvalues, 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
TimeUnitcorresponding to the provided suffix - Throws:
ParseException- if the specified suffix does not match any supported time unit
-
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
Adds a specified amount of time to a givenLocalDateTimeobject.- Parameters:
now- the initialLocalDateTimeinstance to which the time will be addedvalue- the amount of time to add, specified as a long value- Returns:
- a new
LocalDateTimeinstance with the added time
-