title: Java 8 DateTimeFormatter with optional part without seconds
body: <p>There already exists question <a href="https://stackoverflow.com/questions/48280447/java-8-datetimeformatter-with-optional-part">Java 8 DateTimeFormatter with optional part</a>, but the answer for it won't work when optional part is only hours and minutes without seconds:</p>
  
  <pre><code>DateTimeFormatter patternWithOptional = new DateTimeFormatterBuilder()
      .appendPattern("M/d/yyyy[ h:mm]")
      .toFormatter();
  TemporalAccessor tmp = patternWithOptional.parseBest("4/11/2020 1:20", LocalDateTime::from, LocalDate::from);
  System.out.println(tmp);
  System.out.println(tmp.getClass().getSimpleName());
  // prints 2020-04-11, without time
  // class is LocalDate in this case
  </code></pre>
  
  <p>This is because <code>LocalDateTime.from(TemporalAccessor temporal)</code> uses <code>TemporalQueries.LOCAL_TIME</code> to query the <code>temporal</code>.  <code>TemporalQueries.LOCAL_TIME</code>, in turn, requires <code>ChronoField.NANO_OF_DAY</code> to be available from <code>temporal</code>.</p>
  
  <pre><code>System.out.println(patternWithOptional.parse("4/11/2020 1:20"));
  // prints:
  {HourOfAmPm=1, MinuteOfHour=20},ISO resolved to 2020-04-11
  </code></pre>
  
  <p>Since <code>HourOfAmPm</code> and <code>MinuteOfHour</code> are available, the simplest way to achieve what I need, that I could come up with:</p>
  
  <pre><code>private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder()
      .appendPattern("M/d/yyyy[ h:mm]")
      .toFormatter();
  
  public static void main(String[] args) {
      // demo
      System.out.println(parse("3/20/1995"));      // without time
      System.out.println(parse("4/11/2020 1:20")); // with time
  }
  
  private static LocalDateTime parse(String s) {
      TemporalAccessor parsed = FORMATTER.parse(s);
      return LocalDateTime.of(
          LocalDate.from(parsed),
          LocalTime.of(
              parsed.isSupported(ChronoField.HOUR_OF_AMPM)
                  ? (int) ChronoField.HOUR_OF_AMPM.getFrom(parsed)
                  : 0,
              parsed.isSupported(ChronoField.MINUTE_OF_HOUR)
                  ? (int) ChronoField.MINUTE_OF_HOUR.getFrom(parsed)
                  : 0
          ) // minor note: this part could also be used as a lambda argument for parseBest method.
      );
  }
  </code></pre>
  
  <p>Is there a simpler way to do this without explicit <code>isSupported</code> checks?</p>