DateUtils { public static boolean isValidWeekCode(String weekCode) { if (weekCode == null) { return true; } if (!weekCode.matches(WEEK_CODE_PATTERN)) { return false; } int year = getYearFromWeekCode(weekCode); int week = getWeekFromWeekCode(weekCode); int lastWeekOfYear = getLastWeekOfYear(year); return FIRST_WEEK_NUMBER <= week && week <= lastWeekOfYear; } private  DateUtils(); @SuppressWarnings("unchecked") static T createJava8Date(Class<T> clazz, String dateStr, String format); static LocalDate createLocalDate(String dateStr); static LocalDate createLocalDate(String dateStr, String format); static LocalDateTime createLocalDateTime(String dateTimeStr); static LocalDateTime createLocalDateTime(String dateTimeStr, String format); static LocalTime createLocalTime(String timeStr); static LocalTime createLocalTime(String timeStr, String format); static ZonedDateTime createZonedDateTime(String dateTimeStr); static ZonedDateTime createZonedDateTime(String dateTimeStr, String format); static String formatDate(LocalDate date, String format); static String formatDateTime(LocalDateTime dateTime, String format); static String formatJava8Date(Class<?> clazz, Object value, String format); static String formatTime(LocalTime time, String format); static String formatZonedDateTime(ZonedDateTime dateTime, String format); static int getLastWeekOfYear(int year); static String getNextWeekCode(String weekCode); static int getQuarter(LocalDate date); static LocalDate getStartDateOfWeek(String weekCode); static boolean isJava8DateType(Class<?> clazz); static boolean isSupportedDateType(Class<?> clazz); static boolean isValidWeekCode(String weekCode); static Date toLegacyDate(LocalDate d); static Date toLegacyDate(LocalDateTime ldt); static String toWeekCode(LocalDate date); static final String WEEK_CODE_PATTERN; }
@Test public void testIsValidWeekCode() { assertTrue(DateUtils.isValidWeekCode(null)); assertFalse(DateUtils.isValidWeekCode("abc")); assertFalse(DateUtils.isValidWeekCode("2013")); assertFalse(DateUtils.isValidWeekCode("2013-1")); assertFalse(DateUtils.isValidWeekCode("2013-00")); assertTrue(DateUtils.isValidWeekCode("2013-01")); assertTrue(DateUtils.isValidWeekCode("2013-02")); assertTrue(DateUtils.isValidWeekCode("2013-52")); assertFalse(DateUtils.isValidWeekCode("2013-53")); assertFalse(DateUtils.isValidWeekCode("2014-53")); assertTrue(DateUtils.isValidWeekCode("2015-53")); assertFalse(DateUtils.isValidWeekCode("2015-54")); }