这是我的相同
每周重复规则的重复规则示例
RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=MO;UNTIL=20161222T000000Z
RRULE:FREQ=MONTHLY;INTERVAL=<Every month/with some interval>;BYDAY=<Day of week>;UNTIL=<Until Date>
所以按照这个你的规则将是: "RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=MO;UNTIL=20111212T000000Z"
给出的是创建重复规则和日期的代码
class CreateRule{
static {
weekMap.put(Short.valueOf("0"), "SU");
weekMap.put(Short.valueOf("1"), "MO");
weekMap.put(Short.valueOf("2"), "TU");
weekMap.put(Short.valueOf("3"), "WE");
weekMap.put(Short.valueOf("4"), "TH");
weekMap.put(Short.valueOf("5"), "FR");
weekMap.put(Short.valueOf("6"), "SA");
}
Short repeatCountMonthly = repeatCount != null ? repeatCount : 0;
String weekDay = weekMap.get(<repeatMonthWeek>);
//Create recurrence Rule
String monthlyRecurrenceRule = DateUtils.getMonthlyRecurrenceRule(repeatCountMonthly,endsNever, endsAfterOccurrences,endTime,repeatMonthDay,weekDay);
//Create recurrence Dates
Set<LocalDate> monthlyStartDates = CalendarUtils.getRecurrenceDates(monthlyRecurrenceRule,
LocalDate.fromDateFields(startDate));
}
类将具有创建规则和生成日期的方法:
class DateUtils{
public static String getMonthlyRecurrenceRule(Short interval,boolean endsNever,Integer occurrences, StringBuilder endTime,Short dayOfMonth,String dayOfWeek){
StringBuilder monthlyRecurrenceRule = new StringBuilder("RRULE:FREQ=MONTHLY");
if(interval!=null&&interval.intValue()>0)
monthlyRecurrenceRule.append(";INTERVAL=").append(interval.toString());
if(dayOfMonth!=null && dayOfMonth>0)
monthlyRecurrenceRule.append(";BYMONTHDAY=").append(dayOfMonth.toString());
else
monthlyRecurrenceRule.append(";BYDAY=").append(dayOfWeek);
if(endsNever){
//set endtime as startdate+10 years
monthlyRecurrenceRule.append(";UNTIL=").append("20271231T090000Z");
}
else{
if(occurrences!=null&&occurrences.intValue()>0)
monthlyRecurrenceRule.append(";COUNT=").append(occurrences.toString());
else
monthlyRecurrenceRule.append(";UNTIL=").append(endTime.toString());
}
return monthlyRecurrenceRule.toString();
}
public static Set<LocalDate> getRecurrenceDates(String rRule,LocalDate startDate) throws ParseException{
Set<LocalDate> recurrenceDates = new HashSet<LocalDate>();
for (LocalDate date : LocalDateIteratorFactory.createLocalDateIterable(rRule, startDate, true)) {
recurrenceDates.add(date);
}
return recurrenceDates;
}
}