Package org.dspace.util
Class MultiFormatDateParser
- java.lang.Object
-
- org.dspace.util.MultiFormatDateParser
-
public class MultiFormatDateParser extends Object
Attempt to parse date strings in a variety of formats. This uses an external list of regular expressions and associated SimpleDateFormat strings. Inject the list as pairs of strings usingsetPatterns(java.util.Map<java.lang.String, java.lang.String>).parse(java.lang.String)walks the provided list in the order provided and tries each entry against a String. Dates are parsed as being in the UTC zone.- Author:
- mwood
-
-
Constructor Summary
Constructors Constructor Description MultiFormatDateParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] args)static Dateparse(String dateString)Compare a string to each injected regular expression in entry order, and when it matches, attempt to parse it using the associated format.voidsetPatterns(Map<String,String> patterns)
-
-
-
Method Detail
-
parse
public static Date parse(String dateString)
Compare a string to each injected regular expression in entry order, and when it matches, attempt to parse it using the associated format.- Parameters:
dateString- the supposed date to be parsed.- Returns:
- the result of the first successful parse, or
nullif none.
-
main
public static void main(String[] args) throws IOException
- Throws:
IOException
-
-