Package org.pentaho.di.core.util
Class DateDetector
java.lang.Object
org.pentaho.di.core.util.DateDetector
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
detectDateFormat
(String dateString) static String
detectDateFormat
(String dateString, String locale) static String
detectDateFormatBiased
(String dateString, String locale, String desiredKey) Finds a date format that matches the date value given.static String
getDateFormatByRegex
(String regex) static String
getDateFormatByRegex
(String regex, String locale) static org.apache.commons.collections.BidiMap
getDateFormatToRegExps
(String locale) static Date
getDateFromString
(String dateString) static Date
getDateFromString
(String dateString, String locale) static Date
getDateFromStringByFormat
(String dateString, String dateFormat) static String
getRegexpByDateFormat
(String dateFormat) static String
getRegexpByDateFormat
(String dateFormat, String locale) static boolean
isValidDate
(String dateString) static boolean
isValidDate
(String dateString, String dateFormat) static boolean
isValidDateFormatToStringDate
(String dateFormat, String dateString) static boolean
isValidDateFormatToStringDate
(String dateFormat, String dateString, String locale)
-
Method Details
-
getRegexpByDateFormat
- Parameters:
dateFormat
- - date format for get regexp- Returns:
- regexp for given date format
-
getRegexpByDateFormat
- Parameters:
dateFormat
- - date format for get regexp by locale- Returns:
- regexp for given date format
-
getDateFormatByRegex
- 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 usegetDateFormatByRegex(String regex, String locale)
- Returns:
String
string wich represented Date Format
-
getDateFormatByRegex
- Parameters:
regex
- - regexp for parse date format from string by locale- Returns:
String
string wich represented Date Format
-
getDateFromString
- 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
- 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 parsedateFormat
- format which should be applied for string- Returns:
Date
converted from dateString by format- Throws:
ParseException
- if we can not parse date string
-
detectDateFormat
- Parameters:
dateString
- - date string for detect date format- Returns:
String
string which represented Date Format or null
-
detectDateFormat
- Parameters:
dateString
- - date string for detect date format- Returns:
String
string which represented Date Format or null
-
detectDateFormatBiased
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 playdesiredKey
- 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
-
isValidDate
- Parameters:
dateString
- - string for checkdateFormat
- - format for check- Returns:
- true if we can parse string by format without exception
-
isValidDate
- Parameters:
dateString
- - string for check- Returns:
- true if we can parse string without exception
-
isValidDateFormatToStringDate
- Parameters:
dateFormat
- - format which we will try to apply for stringdateString
- - 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 stringdateString
- - string which contains datelocale
- - locale for date format- Returns:
- true if we found that we know dateFormat and it applied for given string
-