2 月の最後の日ごとに日付を繰り返す必要があります。Joda 時間を使用して、日、週、月などの日付を生成するルールを使用しています。
private static List<DateTime> calculateRecurrentDates(DateTime startDate, String recurrentRule) {
List<DateTime> dates = new ArrayList<DateTime>();
TimeStamp startDate = Timestamp.valueOf("2011-02-28 10:10:10");
String recurrentRule = "RRULE:FREQ=YEARLY;COUNT=6;INTERVAL=1;";
String leapYearRule = "RRULE:FREQ=YEARLY;COUNT=6;INTERVAL=1;BYMONTHDAY=28,29;BYSETPOS=-1";
try {
DateTimeIterable range = DateTimeIteratorFactory.createDateTimeIterable(recurrentRule, startDate, DateTimeZone.UTC, true);
for (DateTime date : range) {
dates.add(date);
}
} catch (ParseException e) {
dates = null;
logger.error(e.getMessage());
}
return dates;
}
しかし、私はこれを受け取ります:
2011-02-28T10:10:10.000Z
2012-02-28T10:10:10.000Z
2013-02-28T10:10:10.000Z
2014-02-28T10:10:10.000Z
2015-02-28T10:10:10.000Z
2016-02-28T10:10:10.000Z
うるう年の場合は次のようになります。
2012-02-29T10:10:10.000Z
2012-12-29T10:10:10.000Z
2013-12-29T10:10:10.000Z
2014-12-29T10:10:10.000Z
2015-12-29T10:10:10.000Z
2016-12-29T10:10:10.000Z
2017-12-29T10:10:10.000Z
毎年 2 月の最終日を取得する 1 つのルールを作成するにはどうすればよいですか?