DateTimeUtils { public static boolean isValidDateTime(String s) { return isValidDateTime(s, 0, formats.length - 1); }  static boolean isValidDateTime(String s); static boolean isValidDateTime(String s, int minimumPrecision); static boolean isValidDateTime(String s, int minimumPrecision,
            int maximumPrecision); static final int YEAR_PRECISION; static final int MONTH_PRECISION; static final int DATE_PRECISION; static final int DATETIME_MINUTE_PRECISION; static final int DATETIME_SECOND_PRECISION; static final int DATETIME_MILLISECOND_PRECISION; }
@Test public void testIsValidDateTimeString() { assertTrue(isValidDateTime("2009")); assertTrue(isValidDateTime("200902")); assertTrue(isValidDateTime("20090228")); assertTrue(isValidDateTime("200902281205")); assertTrue(isValidDateTime("200902281205+0001")); assertTrue(isValidDateTime("20090228120556")); assertTrue(isValidDateTime("20090228120556+0001")); assertTrue(isValidDateTime("20090228120556.123")); assertTrue(isValidDateTime("20090228120556.123+0200")); assertFalse(isValidDateTime("200913")); assertFalse(isValidDateTime("20090230")); assertFalse(isValidDateTime("200902282505")); assertFalse(isValidDateTime("200902281205+9999")); assertFalse(isValidDateTime("20090228120599")); assertFalse(isValidDateTime("20090228120599+9999")); assertFalse(isValidDateTime("20090228120556.12345")); assertFalse(isValidDateTime("20090228120556.123+9999")); }
@Test public void testIsValidDateTimeMinimumPrecision() { assertTrue(isValidDateTime("2009", YEAR_PRECISION)); assertTrue(isValidDateTime("200902", MONTH_PRECISION)); assertTrue(isValidDateTime("20090228", DATE_PRECISION)); assertTrue(isValidDateTime("200902281205", DATETIME_MINUTE_PRECISION)); assertTrue(isValidDateTime("200902281205+0001", DATETIME_MINUTE_PRECISION)); assertTrue(isValidDateTime("20090228120556", DATETIME_SECOND_PRECISION)); assertTrue(isValidDateTime("20090228120556+0001", DATETIME_MINUTE_PRECISION)); assertTrue(isValidDateTime("20090228120556.123", DATETIME_MINUTE_PRECISION)); assertTrue(isValidDateTime("20090228120556.123+0200", DATETIME_MINUTE_PRECISION)); assertFalse(isValidDateTime("2009", DATETIME_MINUTE_PRECISION)); assertFalse(isValidDateTime("2009", DATE_PRECISION)); assertFalse(isValidDateTime("20090230", DATETIME_MINUTE_PRECISION)); }
@Test public void testIsValidDateTimeExactPrecision() { assertTrue(isValidDateTime("2009", YEAR_PRECISION, YEAR_PRECISION)); assertTrue(isValidDateTime("200902", YEAR_PRECISION, MONTH_PRECISION)); assertTrue(isValidDateTime("20090228", YEAR_PRECISION, DATE_PRECISION)); assertTrue(isValidDateTime("200902281205", DATE_PRECISION, DATETIME_MINUTE_PRECISION)); assertTrue(isValidDateTime("200902281205+0001", DATE_PRECISION, DATETIME_MINUTE_PRECISION)); assertTrue(isValidDateTime("20090228120556", DATETIME_SECOND_PRECISION, DATETIME_SECOND_PRECISION)); assertFalse(isValidDateTime("2009", DATE_PRECISION, DATE_PRECISION)); assertFalse(isValidDateTime("20090230", YEAR_PRECISION, YEAR_PRECISION)); }