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 DateTimeFormatter patterns. Inject the list as pairs of strings using setPatterns(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 Details

    • MultiFormatDateParser

      public MultiFormatDateParser()
  • Method Details

    • setPatterns

      @Inject public void setPatterns(Map<String,String> patterns)
    • parse

      public static ZonedDateTime 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 null if none.
    • main

      public static void main(String[] args) throws IOException
      Throws:
      IOException