class StringToTimestamp {

  @Udf(description = "Converts a string representation of a date in the given format"
      + " into the BIGINT value that represents the millisecond timestamp."
      + " Single quotes in the timestamp format can be escaped with '',"
      + " for example: 'yyyy-MM-dd''T''HH:mm:ssX'.")
  public long stringToTimestamp(
      @UdfParameter(
          description = "The string representation of a date.") final String formattedTimestamp,
      @UdfParameter(
          description = "The format pattern should be in the format expected by"
              + " java.time.format.DateTimeFormatter.") final String formatPattern) {
    try {
      final StringToTimestampParser timestampParser = parsers.get(formatPattern);
      return timestampParser.parse(formattedTimestamp);
    } catch (final ExecutionException | RuntimeException e) {
      throw new KsqlFunctionException("Failed to parse timestamp '" + formattedTimestamp
           + "' with formatter '" + formatPattern
          + "': " + e.getMessage(), e);
    }
  }

}