@Udf(description = "Converts the number of days since 1970-01-01 00:00:00 UTC/GMT to a date "
      + "string using the given format pattern. The format pattern should be in the format"
      + " expected by java.time.format.DateTimeFormatter")
  public String formatDate(
      @UdfParameter(
          description = "The date to convert") final Date date,
      @UdfParameter(
          description = "The format pattern should be in the format expected by"
              + " java.time.format.DateTimeFormatter.") final String formatPattern) {
    if (date == null || formatPattern == null) {
      return null;
    }
    try {
      final DateTimeFormatter formatter = formatters.get(formatPattern);
      return LocalDate.ofEpochDay(TimeUnit.MILLISECONDS.toDays(date.getTime())).format(formatter);
    } catch (final ExecutionException | RuntimeException e) {
      throw new KsqlFunctionException("Failed to format date " + date
          + " with formatter '" + formatPattern
          + "': " + e.getMessage(), e);
    }
  }
@Test
  public void shouldRoundTripWithStringToDate() {
    final String format = "dd/MM/yyyy'Freya'";
    final ParseDate parseDate = new ParseDate();
    IntStream.range(-10_000, 20_000)
        .parallel()
        .forEach(idx -> {
          final String result = udf.formatDate(new Date(idx * 86400000L), format);
          final Date date = parseDate.parseDate(result, format);
          assertThat(date.getTime(), is(idx * 86400000L));
        });
  }