@Test public void testParseDateAsDuration() { OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1); long parsedMilliseconds = DateTimeUtils.parseDateAsDuration(oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME)); assertTrue(parsedMilliseconds <= MINUTE_IN_MILLISECONDS, "Parsed date as duration is bigger than " + MINUTE_IN_MILLISECONDS); assertTrue(parsedMilliseconds > FIFTY_NINE_SECONDS_IN_MILLISECONDS, "Parsed date as duration is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedMilliseconds); }
public static long parseDateAsDuration(String dateTimeStr) { try { OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME); Duration duration = Duration.between(OffsetDateTime.now(), dateTime); return duration.toMillis(); } catch (Exception e) { return TimeUtils.parseTimeString(dateTimeStr); } }
DateTimeUtils extends TimeUtils { public static long parseDateAsDuration(String dateTimeStr) { try { OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME); Duration duration = Duration.between(OffsetDateTime.now(), dateTime); return duration.toMillis(); } catch (Exception e) { return TimeUtils.parseTimeString(dateTimeStr); } } }
DateTimeUtils extends TimeUtils { public static long parseDateAsDuration(String dateTimeStr) { try { OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME); Duration duration = Duration.between(OffsetDateTime.now(), dateTime); return duration.toMillis(); } catch (Exception e) { return TimeUtils.parseTimeString(dateTimeStr); } }  }
DateTimeUtils extends TimeUtils { public static long parseDateAsDuration(String dateTimeStr) { try { OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME); Duration duration = Duration.between(OffsetDateTime.now(), dateTime); return duration.toMillis(); } catch (Exception e) { return TimeUtils.parseTimeString(dateTimeStr); } }  static boolean isRepeatable(String dateTimeStr); static boolean isPeriod(String dateTimeStr); static boolean isNumeric(String dateTimeStr); static long parseDateTime(String dateTimeStr); static long parseDuration(String durationStr); static long parseDateAsDuration(String dateTimeStr); static String[] parseISORepeatable(String isoString); static long[] parseRepeatableDateTime(String dateTimeStr); }
DateTimeUtils extends TimeUtils { public static long parseDateAsDuration(String dateTimeStr) { try { OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME); Duration duration = Duration.between(OffsetDateTime.now(), dateTime); return duration.toMillis(); } catch (Exception e) { return TimeUtils.parseTimeString(dateTimeStr); } }  static boolean isRepeatable(String dateTimeStr); static boolean isPeriod(String dateTimeStr); static boolean isNumeric(String dateTimeStr); static long parseDateTime(String dateTimeStr); static long parseDuration(String durationStr); static long parseDateAsDuration(String dateTimeStr); static String[] parseISORepeatable(String isoString); static long[] parseRepeatableDateTime(String dateTimeStr);  }