Class TimeParser

java.lang.Object
one.tranic.t.base.parse.time.TimeParser

public class TimeParser extends Object
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 Details

    • TimeParser

      public TimeParser()
  • Method Details

    • parse

      public static String parse(String arg) throws ParseException
      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 a LocalDateTime object.
      Parameters:
      timeString - the string representing the time to parse; must conform to the expected format or be the literal "forever"
      Returns:
      the parsed LocalDateTime object based on the input string
      Throws:
      ParseException - if the input string is invalid or cannot be parsed into a LocalDateTime
      ForeverNonException - if the input string is the literal "forever"
    • isTimeInPast

      public static boolean isTimeInPast(LocalDateTime dateTime)
      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