/** * Creates {@code DayOfWeek} for given string. * * @param text the text to be parsed to {@code DayOfWeek} * @return the {@code DayOfWeek} created from text, null if {@code text} isn't equal to one of * weekdays short names */ public static DayOfWeek parse(String text) { for (DayOfWeek dayOfWeek : DayOfWeek.values()) { if (dayOfWeek.name().equalsIgnoreCase(text) || dayOfWeek.getShortName().equalsIgnoreCase(text)) { return dayOfWeek; } } return null; }
/** * Returns {@code DayOfWeek} for given number. * * @param dayOfWeek the day of week as a number * @return the {@code DayOfWeek} * @throws IllegalArgumentException if given number isn't between 1 and 7 */ public static DayOfWeek getDayOfWeek(int dayOfWeek) { for (DayOfWeek day : DayOfWeek.values()) { if (day.getValue() == dayOfWeek) { return day; } } throw new IllegalArgumentException("Not a valid day"); }
private List<DayOfWeek> createDayOfWeeks(List<Object> list) { List<DayOfWeek> dayOfWeeks = new ArrayList<>(list.size()); for (Object item : list) { DayOfWeek dayOfWeek = DayOfWeek.parse(item.toString()); if (dayOfWeek != null) { dayOfWeeks.add(dayOfWeek); } } return dayOfWeeks; }
/** * Creates {@code DayOfWeek} for given property. * * @param property the {@code DateTime.Property} to be parsed to {@code DayOfWeek} * @return the {@code DayOfWeek} parsed from {@code DateTime.Property} */ public static DayOfWeek getDayOfWeek(DateTime.Property property) { return DayOfWeek.getDayOfWeek(property.get()); }
/** * Creates {@code DayOfWeek} for given date. * * @param date the {@code LocalDate} to be parsed to {@code DayOfWeek} * @return the {@code DayOfWeek} parsed from {@code LocalDate} */ public static DayOfWeek getDayOfWeek(LocalDate date) { return DayOfWeek.getDayOfWeek(date.dayOfWeek().get()); }