From f939783d70cddc72d8593dc49223735820c0b57a Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 24 Nov 2011 14:28:55 +0000 Subject: [PATCH] ALF-6356 Correct repeating events handling of the last instance by day git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32282 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/calendar/CalendarHelpersTest.java | 23 +++++++++++++++++++ .../calendar/CalendarRecurrenceHelper.java | 8 ++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/source/java/org/alfresco/repo/calendar/CalendarHelpersTest.java b/source/java/org/alfresco/repo/calendar/CalendarHelpersTest.java index db85f20ccc..50365b4ed5 100644 --- a/source/java/org/alfresco/repo/calendar/CalendarHelpersTest.java +++ b/source/java/org/alfresco/repo/calendar/CalendarHelpersTest.java @@ -201,6 +201,18 @@ public class CalendarHelpersTest assertEquals("2011-07-29", dateFmt.format(dates.get(9))); + // From before today, full time set + dates.clear(); + currentDate.set(2011,11-1,24,10,30); + RecurrenceHelper.buildDailyRecurrences( + currentDate, dates, null, + date(2011,11,22,12,30), date(2011,11,25,12,30), + false, 1); + assertEquals(2, dates.size()); + assertEquals("2011-11-24", dateFmt.format(dates.get(0))); // Thu + assertEquals("2011-11-25", dateFmt.format(dates.get(1))); // Fri + + // With no end date but only first, check it behaves dates.clear(); currentDate.set(2011,7-1,19,10,30); @@ -269,6 +281,17 @@ public class CalendarHelpersTest assertEquals("2011-07-25", dateFmt.format(dates.get(1))); // Mon + // Just before today, full time set + dates.clear(); + currentDate.set(2011,11-1,24,10,30); + RecurrenceHelper.buildWeeklyRecurrences( + currentDate, dates, params, + date(2011,11,22,12,30), date(2011,11,25,12,30), + false, 1); + assertEquals(1, dates.size()); + assertEquals("2011-11-24", dateFmt.format(dates.get(0))); // Thu + + // From today dates.clear(); currentDate.set(2011,7-1,19,10,30); diff --git a/source/java/org/alfresco/service/cmr/calendar/CalendarRecurrenceHelper.java b/source/java/org/alfresco/service/cmr/calendar/CalendarRecurrenceHelper.java index 2938a486ba..20abffb03d 100644 --- a/source/java/org/alfresco/service/cmr/calendar/CalendarRecurrenceHelper.java +++ b/source/java/org/alfresco/service/cmr/calendar/CalendarRecurrenceHelper.java @@ -127,7 +127,8 @@ public class CalendarRecurrenceHelper * For the given Calendar Entry, return its subsequent Recurrence on or after * the specified date, until the given limit. If it doesn't have any recurrences * on or after the start date (either no recurrence rules, or the last recurrence - * date is before then), null will be returned. + * date is before then), null will be returned. (The onOrAfter and until dates + * are treat as inclusive) * If requested, can stop after the first hit * @return The next recurrence on or after the given date, or null if there aren't any */ @@ -143,7 +144,8 @@ public class CalendarRecurrenceHelper * For the given Calendar Entry, return its subsequent Recurrence on or after * the specified date, until the given limit. If it doesn't have any recurrences * on or after the start date (either no recurrence rules, or the last recurrence - * date is before then), null will be returned. + * date is before then), null will be returned. (The onOrAfter and until dates + * are treat as inclusive) * If requested, can stop after the first hit * @return The next recurrence on or after the given date, or null if there aren't any */ @@ -273,7 +275,7 @@ public class CalendarRecurrenceHelper else { // Run until the end - while (currentDate.getTime().before(until)) + while (! currentDate.getTime().after(until)) { dates.add(currentDate.getTime()); currentDate.add(Calendar.DATE, 1);