Class DateTimeValidator

java.lang.Object
io.github.perceivechuchu.datetimeutil.validator.DateTimeValidator

public class DateTimeValidator extends Object
This class is a utility for date time validations
Since:
2.1.0
Author:
Perceive Chuchu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static List<String>
    The holder for all the date format list items
    protected static String
    The location of the file that contains date format patterns
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static List<String>
    Gets all the date format patterns in a file
    static boolean
    isValid(String dateTimeText)
    Validates the date and time in textual format.
    static boolean
    isValid(String dateTimeText, String dateFormatPattern)
    Validates the date and time in textual format with the date format pattern to validate against.
    static boolean
    isValid(String dateTimeText, Locale locale)
    Validates the date and time in textual format with the locale
    static boolean
    isValid(String dateTimeText, Locale locale, String dateFormatPattern)
    Validates the date and time in textual format with locale and the date format pattern to validate against
    protected static void
    Loads date format patterns from a file

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fileLocation

      protected static String fileLocation
      The location of the file that contains date format patterns
      Since:
      2.1.0
    • dateFormats

      protected static List<String> dateFormats
      The holder for all the date format list items
      Since:
      2.1.0
  • Method Details

    • isValid

      public static boolean isValid(String dateTimeText)
      Validates the date and time in textual format. This method uses the default locale -> "Locale.ENGLISH"
      Parameters:
      dateTimeText - the date time text to be validated
      Returns:
      the boolean flag to indicate validity of the supplied datetime text
      Throws:
      IllegalArgumentException - if parameter is not valid or the date string or pattern array is null
      Since:
      2.1.0
    • isValid

      public static boolean isValid(String dateTimeText, Locale locale)
      Validates the date and time in textual format with the locale
      Parameters:
      dateTimeText - the date time text to be validated
      locale - the locale for the dateTimeText value
      Returns:
      the boolean flag to indicate validity of the supplied datetime text
      Throws:
      IllegalArgumentException - if parameter is not valid or the date string or pattern array is null
      Since:
      2.1.0
    • isValid

      public static boolean isValid(String dateTimeText, String dateFormatPattern)
      Validates the date and time in textual format with the date format pattern to validate against. This method uses the default locale -> "Locale.ENGLISH"
      Parameters:
      dateTimeText - the date time text to be validated
      dateFormatPattern - the date format pattern to validate against
      Returns:
      the boolean flag to indicate validity of the supplied datetime text
      Throws:
      IllegalArgumentException - if parameter is not valid or the date string or pattern array is null
      Since:
      2.1.0
    • isValid

      public static boolean isValid(String dateTimeText, Locale locale, String dateFormatPattern)
      Validates the date and time in textual format with locale and the date format pattern to validate against
      Parameters:
      dateTimeText - the date time text to be validated
      locale - the locale for the dateTimeText value
      dateFormatPattern - the date format pattern to validate against
      Returns:
      the boolean flag to indicate validity of the supplied datetime text
      Throws:
      IllegalArgumentException - if parameter is not valid or the date string or pattern array is null
      Since:
      2.1.0
    • loadDateFormats

      protected static void loadDateFormats()
      Loads date format patterns from a file
      Since:
      2.1.0
    • getFileFromResourceAsStream

      protected static List<String> getFileFromResourceAsStream()
      Gets all the date format patterns in a file
      Returns:
      the list of date format patterns form a file
      Throws:
      DateTimeValidationException - thrown when date format pattern file is not found.
      Since:
      2.1.0