class StringToDate {

  @Udf(description = "Converts formattedDate, a string representation of a date into"
      + " an integer representing days since epoch using the given formatPattern.")
  public int stringToDate(
      @UdfParameter(
          description = "The string representation of a date.") final String formattedDate,
      @UdfParameter(
          description = "The format pattern should be in the format expected by"
              + " java.time.format.DateTimeFormatter.") final String formatPattern) {
    try {
      final DateTimeFormatter formatter = formatters.get(formatPattern);
      return ((int)LocalDate.parse(formattedDate, formatter).toEpochDay());
    } catch (final ExecutionException | RuntimeException e) {
      throw new KsqlFunctionException("Failed to parse date '" + formattedDate
          + "' with formatter '" + formatPattern
          + "': " + e.getMessage(), e);
    }
  }

}