Package one.tranic.t.base.parse.time
Class TimeParser
java.lang.Object
one.tranic.t.base.parse.time.TimeParser
The TimeParser class provides functionality for parsing time-related string inputs
and performing operations such as calculating future times, validating time formats,
and checking time conditions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisTimeInPast(LocalDateTime dateTime) Checks if the given LocalDateTime is earlier than the current time.static StringParses a time argument string and returns the formatted future time or a special value such as "forever".static LocalDateTimeparseStringTime(String timeString) Parses a string representation of a time into aLocalDateTimeobject.
-
Constructor Details
-
TimeParser
public TimeParser()
-
-
Method Details
-
parse
Parses a time argument string and returns the formatted future time or a special value such as "forever".- Parameters:
arg- the time argument as a string; can be literal "forever" or a duration string with a valid unit- Returns:
- a formatted string representing the calculated future time, or the literal "forever" for the special case
- Throws:
ParseException- if the argument is null, empty, contains invalid characters, has an unsupported unit, or if the numeric portion of the duration is invalid
-
parseStringTime
public static LocalDateTime parseStringTime(String timeString) throws ParseException, ForeverNonException Parses a string representation of a time into aLocalDateTimeobject.- Parameters:
timeString- the string representing the time to parse; must conform to the expected format or be the literal "forever"- Returns:
- the parsed
LocalDateTimeobject based on the input string - Throws:
ParseException- if the input string is invalid or cannot be parsed into aLocalDateTimeForeverNonException- if the input string is the literal "forever"
-
isTimeInPast
Checks if the given LocalDateTime is earlier than the current time.- Parameters:
dateTime- the LocalDateTime object to check- Returns:
- true if the specified time is in the past; false otherwise
-