class DateToString {

  @Udf(description = "Converts an integer representing days since epoch to a string"
      + " using the given format pattern. The format pattern should be in the format"
      + " expected by java.time.format.DateTimeFormatter")
  public String dateToString(
      @UdfParameter(
          description = "The Epoch Day to convert,"
              + " based on the epoch 1970-01-01") final int epochDays,
      @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 LocalDate.ofEpochDay(epochDays).format(formatter);
    } catch (final ExecutionException | RuntimeException e) {
      throw new KsqlFunctionException("Failed to format date " + epochDays
          + " with formatter '" + formatPattern
          + "': " + e.getMessage(), e);
    }
  }

}