ParameterUtil { public static Timestamp parseBest(String value) { List<Function<String, Instant>> functions = List.of( ParameterUtil::parseDate, ParameterUtil::parseDateHour, ParameterUtil::parseDateMonth, ParameterUtil::parseDateYear, Instant::parse ); for (Function<String, Instant> function : functions) { try { Instant instant = function.apply(value); return Timestamp.newBuilder().setSeconds(instant.getEpochSecond()).build(); } catch (DateTimeParseException e) {} } var msg = "Could not parse: " + value; LOG.error(msg); throw new DateTimeException(msg); } private  ParameterUtil(); static Instant parseDate(String date); static Instant parseDateHour(String dateHour); static Instant parseDateMonth(String dateMonth); static Instant parseDateYear(String dateYear); static String toParameter(Schedule schedule, Instant instant); static Timestamp parseBest(String value); static Instant parseAlignedInstant(String dateHour, Schedule schedule);  }
@Test @Parameters({ "2016-01-19, 2016-01-19T00:00:00Z", "2016-01-19T09, 2016-01-19T09:00:00Z", "2016-01, 2016-01-01T00:00:00Z", "2016, 2016-01-01T00:00:00Z", "2016-01-19T09:11:00Z, 2016-01-19T09:11:00Z", "2016-01-19T09:11:01Z, 2016-01-19T09:11:01Z", }) public void testParseBest(String string, String timestamp) { long expected = Instant.parse(timestamp).getEpochSecond(); long result = ParameterUtil.parseBest(string).getSeconds(); assertEquals(result, expected); }