Answer to first question:
public static List<LocalDate> getDaysOfYear(int year, List<LocalDate> holidays) {
LocalDate date = new LocalDate(year, 1, 1);
LocalDate end = new LocalDate(year + 1, 1, 1);
List<LocalDate> list = new ArrayList<LocalDate>();
while (date.isBefore(end)) {
if (!holidays.contains(date)) {
list.add(date);
}
date = date.plusDays(1);
}
return Collections.unmodifiableList(list);
}
Answer to second question:
LocalDate date = LocalDate.now();
int dow = date.getDayOfWeek();
// dow has the values 1=Monday, 2=Tuesday, ..., 7=Sunday
UPDATE for question 2:
An alternative to using numbers (or named constants like DateTimeConstants.MONDAY which are finally only numbers, too) is to use the property dayOfWeek().getAsText(). It allows access to localized names like "Monday" (English) or "Lundi" (French).
See this code example:
LocalDate date = LocalDate.now();
String nameOfWeekday = date.dayOfWeek().getAsText(Locale.ENGLISH);
For such date-only problems the type LocalDate
is by far the most simple and straight-forward one to use. The type DateTime
only makes sense if you have a time part and a need for timezone calculations.