Package org.pentaho.di.core.util
Class DateDetector
- java.lang.Object
-
- org.pentaho.di.core.util.DateDetector
-
public class DateDetector extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringdetectDateFormat(String dateString)static StringdetectDateFormat(String dateString, String locale)static StringdetectDateFormatBiased(String dateString, String locale, String desiredKey)Finds a date format that matches the date value given.static StringgetDateFormatByRegex(String regex)static StringgetDateFormatByRegex(String regex, String locale)static org.apache.commons.collections.BidiMapgetDateFormatToRegExps(String locale)static DategetDateFromString(String dateString)static DategetDateFromString(String dateString, String locale)static DategetDateFromStringByFormat(String dateString, String dateFormat)static StringgetRegexpByDateFormat(String dateFormat)static StringgetRegexpByDateFormat(String dateFormat, String locale)static booleanisValidDate(String dateString)static booleanisValidDate(String dateString, String dateFormat)static booleanisValidDateFormatToStringDate(String dateFormat, String dateString)static booleanisValidDateFormatToStringDate(String dateFormat, String dateString, String locale)
-
-
-
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 usegetDateFormatByRegex( String regex, String locale )- Returns:
Stringstring 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:
Stringstring wich represented Date Format
-
getDateFromString
public static Date getDateFromString(String dateString) throws ParseException
- Parameters:
dateString- date string for parse- Returns:
Dateconverted 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:
Dateconverted 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:
Dateconverted 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:
Stringstring which represented Date Format or null
-
detectDateFormat
public static String detectDateFormat(String dateString, String locale)
- Parameters:
dateString- - date string for detect date format- Returns:
Stringstring 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 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
public static org.apache.commons.collections.BidiMap getDateFormatToRegExps(String locale)
-
isValidDate
public static boolean isValidDate(String dateString, String dateFormat)
- Parameters:
dateString- - string for checkdateFormat- - 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 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
-
-