// Test getWeeksInWeekYear(). // If we avoid the first week of January and the last week of // December, getWeeksInWeekYear() and // getActualMaximum(WEEK_OF_YEAR) values should be the same. for (int year = 2000; year <= 2100; year++) {
cal.clear();
cal.set(year, JUNE, 1); int n = cal.getWeeksInWeekYear(); if (n != cal.getActualMaximum(WEEK_OF_YEAR)) {
String s = String.format("getWeeksInWeekYear() = %d, "
+ "getActualMaximum(WEEK_OF_YEAR) = %d%n",
n, cal.getActualMaximum(WEEK_OF_YEAR)); thrownew RuntimeException(s);
}
cal.setWeekDate(cal.getWeekYear(), n, SUNDAY); if (cal.getWeeksInWeekYear() != n) {
String s = String.format("last day: got %d, expected %d%n",
cal.getWeeksInWeekYear(), n); thrownew RuntimeException(s);
}
}
// Test lenient mode with out of range values. for (int[][] dates : leniencyData) { int[] expected = dates[0]; int[] weekDate = dates[1]; // Convert ISO 8601 day-of-week to Calendar.DAY_OF_WEEK. int dayOfWeek = getCalendarDayOfWeek(weekDate[2]);
// Test non-lenient mode
cal.setLenient(false); for (int[] date : invalidData) {
cal.clear(); try { // Use the raw dayOfWeek value as invalid data
cal.setWeekDate(date[0], date[1], date[2]);
String s = String.format("didn't throw an IllegalArgumentException with"
+ " %d, %d, %d",date[0], date[1], date[2]); thrownew RuntimeException(s);
} catch (IllegalArgumentException e) { // OK
}
}
}
privatestatic GregorianCalendar newCalendar() { // Use GMT to avoid any surprises related DST transitions.
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); if (!cal.isWeekDateSupported()) { thrownew RuntimeException("Week dates not supported");
} // Setup the ISO 8601 compatible parameters
cal.setFirstDayOfWeek(MONDAY);
cal.setMinimalDaysInFirstWeek(4); return cal;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.