Class DateDetector


  • public class DateDetector
    extends Object
    • Method Detail

      • getRegexpByDateFormat

        public static String getRegexpByDateFormat​(String dateFormat)
        Parameters:
        dateFormat - - date format for get regexp
        Returns:
        regexp for given date format
      • getRegexpByDateFormat

        public static String getRegexpByDateFormat​(String dateFormat,
                                                   String locale)
        Parameters:
        dateFormat - - date format for get regexp by locale
        Returns:
        regexp for given date format
      • getDateFormatByRegex

        public static String getDateFormatByRegex​(String regex)
        Parameters:
        regex - - regexp for parse date format from string
        NOTES: if regex could be used for US and EU locale. It returns europeans locale. For en_US locale please use getDateFormatByRegex( String regex, String locale )
        Returns:
        String string wich represented Date Format
      • getDateFormatByRegex

        public static String getDateFormatByRegex​(String regex,
                                                  String locale)
        Parameters:
        regex - - regexp for parse date format from string by locale
        Returns:
        String string wich represented Date Format
      • getDateFromString

        public static Date getDateFromString​(String dateString)
                                      throws ParseException
        Parameters:
        dateString - date string for parse
        Returns:
        Date converted from dateString by detected format
        Throws:
        ParseException - - if we can not detect date format for string or we can not parse date string
      • getDateFromString

        public static Date getDateFromString​(String dateString,
                                             String locale)
                                      throws ParseException
        Parameters:
        dateString - date string for parse
        Returns:
        Date converted from dateString by detected format
        Throws:
        ParseException - - if we can not detect date format for string or we can not parse date string
      • getDateFromStringByFormat

        public static Date getDateFromStringByFormat​(String dateString,
                                                     String dateFormat)
                                              throws ParseException
        Parameters:
        dateString - date string for parse
        dateFormat - format which should be applied for string
        Returns:
        Date converted from dateString by format
        Throws:
        ParseException - if we can not parse date string
      • detectDateFormat

        public static String detectDateFormat​(String dateString)
        Parameters:
        dateString - - date string for detect date format
        Returns:
        String string which represented Date Format or null
      • detectDateFormat

        public static String detectDateFormat​(String dateString,
                                              String locale)
        Parameters:
        dateString - - date string for detect date format
        Returns:
        String string which represented Date Format or null
      • detectDateFormatBiased

        public static String detectDateFormatBiased​(String dateString,
                                                    String locale,
                                                    String desiredKey)
        Finds a date format that matches the date value given. Will try the desiredKey format before attempting others. The first to match is returned.
        Parameters:
        dateString - the literal value of the date (eg: "01/01/2001")
        locale - the locale in play
        desiredKey - the desired format (should be a valid key to DATE_FORMAT_TO_REGEXPS)
        Returns:
        The key to the format that matched or null if none found.
      • getDateFormatToRegExps

        public static org.apache.commons.collections.BidiMap getDateFormatToRegExps​(String locale)
      • isValidDate

        public static boolean isValidDate​(String dateString,
                                          String dateFormat)
        Parameters:
        dateString - - string for check
        dateFormat - - format for check
        Returns:
        true if we can parse string by format without exception
      • isValidDate

        public static boolean isValidDate​(String dateString)
        Parameters:
        dateString - - string for check
        Returns:
        true if we can parse string without exception
      • isValidDateFormatToStringDate

        public static boolean isValidDateFormatToStringDate​(String dateFormat,
                                                            String dateString)
        Parameters:
        dateFormat - - format which we will try to apply for string
        dateString - - string which contains date
        Returns:
        true if we found that we know dateFormat and it applied for given string
      • isValidDateFormatToStringDate

        public static boolean isValidDateFormatToStringDate​(String dateFormat,
                                                            String dateString,
                                                            String locale)
        Parameters:
        dateFormat - - format which we will try to apply for string
        dateString - - string which contains date
        locale - - locale for date format
        Returns:
        true if we found that we know dateFormat and it applied for given string