mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-6355 Finish interval skipping support in repeating events, and add tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32516 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -206,11 +206,25 @@ public class CalendarHelpersTest
|
|||||||
currentDate.set(2011,11-1,24,10,30);
|
currentDate.set(2011,11-1,24,10,30);
|
||||||
RecurrenceHelper.buildDailyRecurrences(
|
RecurrenceHelper.buildDailyRecurrences(
|
||||||
currentDate, dates, null,
|
currentDate, dates, null,
|
||||||
date(2011,11,22,12,30), date(2011,11,25,12,30),
|
date(2011,11,22,12,30), date(2011,11,27,12,30),
|
||||||
false, 1);
|
false, 1);
|
||||||
assertEquals(2, dates.size());
|
assertEquals(4, dates.size());
|
||||||
assertEquals("2011-11-24", dateFmt.format(dates.get(0))); // Thu
|
assertEquals("2011-11-24", dateFmt.format(dates.get(0))); // Thu
|
||||||
assertEquals("2011-11-25", dateFmt.format(dates.get(1))); // Fri
|
assertEquals("2011-11-25", dateFmt.format(dates.get(1))); // Fri
|
||||||
|
assertEquals("2011-11-26", dateFmt.format(dates.get(2))); // Sat
|
||||||
|
assertEquals("2011-11-27", dateFmt.format(dates.get(3))); // Sun
|
||||||
|
|
||||||
|
// From before today, with an interval
|
||||||
|
// Repeats are 24th, 27th, (30th - too far)
|
||||||
|
dates.clear();
|
||||||
|
currentDate.set(2011,11-1,24,10,30);
|
||||||
|
RecurrenceHelper.buildDailyRecurrences(
|
||||||
|
currentDate, dates, null,
|
||||||
|
date(2011,11,22,12,30), date(2011,11,27,12,30),
|
||||||
|
false, 3);
|
||||||
|
assertEquals(2, dates.size());
|
||||||
|
assertEquals("2011-11-24", dateFmt.format(dates.get(0))); // Thu
|
||||||
|
assertEquals("2011-11-27", dateFmt.format(dates.get(1))); // Sun
|
||||||
|
|
||||||
|
|
||||||
// With no end date but only first, check it behaves
|
// With no end date but only first, check it behaves
|
||||||
@@ -473,6 +487,17 @@ public class CalendarHelpersTest
|
|||||||
assertEquals("2011-09-02", dateFmt.format(dates.get(1)));
|
assertEquals("2011-09-02", dateFmt.format(dates.get(1)));
|
||||||
|
|
||||||
|
|
||||||
|
// Now with a recurrence interval of only every 2 months
|
||||||
|
dates.clear();
|
||||||
|
currentDate.set(2011,7-1,19,10,30);
|
||||||
|
RecurrenceHelper.buildMonthlyRecurrences(
|
||||||
|
currentDate, dates, params,
|
||||||
|
date(2011,7,20), date(2011,9,20),
|
||||||
|
false, 2);
|
||||||
|
assertEquals(1, dates.size());
|
||||||
|
assertEquals("2011-09-02", dateFmt.format(dates.get(0)));
|
||||||
|
|
||||||
|
|
||||||
// With no end date but only first, check it behaves
|
// With no end date but only first, check it behaves
|
||||||
dates.clear();
|
dates.clear();
|
||||||
currentDate.set(2011,7-1,2,10,30);
|
currentDate.set(2011,7-1,2,10,30);
|
||||||
|
@@ -254,7 +254,7 @@ public class CalendarRecurrenceHelper
|
|||||||
// Nice and easy
|
// Nice and easy
|
||||||
while (currentDate.getTime().before(onOrAfter))
|
while (currentDate.getTime().before(onOrAfter))
|
||||||
{
|
{
|
||||||
currentDate.add(Calendar.DATE, 1);
|
currentDate.add(Calendar.DATE, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstOnly)
|
if (firstOnly)
|
||||||
@@ -278,7 +278,7 @@ public class CalendarRecurrenceHelper
|
|||||||
while (! currentDate.getTime().after(until))
|
while (! currentDate.getTime().after(until))
|
||||||
{
|
{
|
||||||
dates.add(currentDate.getTime());
|
dates.add(currentDate.getTime());
|
||||||
currentDate.add(Calendar.DATE, 1);
|
currentDate.add(Calendar.DATE, interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,7 +355,7 @@ public class CalendarRecurrenceHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static void buildMonthlyRecurrences(Calendar currentDate, List<Date> dates,
|
protected static void buildMonthlyRecurrences(Calendar currentDate, List<Date> dates,
|
||||||
Map<String,String> params, Date onOrAfter, Date until, boolean firstOnly, int interval)
|
Map<String,String> params, Date onOrAfter, Date until, boolean firstOnly, int monthInterval)
|
||||||
{
|
{
|
||||||
if (params.get("BYMONTHDAY") != null)
|
if (params.get("BYMONTHDAY") != null)
|
||||||
{
|
{
|
||||||
@@ -364,7 +364,7 @@ public class CalendarRecurrenceHelper
|
|||||||
if (currentDate.get(Calendar.DAY_OF_MONTH) > dayOfMonth)
|
if (currentDate.get(Calendar.DAY_OF_MONTH) > dayOfMonth)
|
||||||
{
|
{
|
||||||
// Move forward to start of the next month
|
// Move forward to start of the next month
|
||||||
addMonthToDayOfMonth(currentDate, dayOfMonth);
|
addMonthToDayOfMonth(currentDate, dayOfMonth, monthInterval);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -375,7 +375,7 @@ public class CalendarRecurrenceHelper
|
|||||||
// Go until in the ok range
|
// Go until in the ok range
|
||||||
while (currentDate.getTime().before(onOrAfter))
|
while (currentDate.getTime().before(onOrAfter))
|
||||||
{
|
{
|
||||||
addMonthToDayOfMonth(currentDate, dayOfMonth);
|
addMonthToDayOfMonth(currentDate, dayOfMonth, monthInterval);
|
||||||
}
|
}
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -393,7 +393,7 @@ public class CalendarRecurrenceHelper
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
addMonthToDayOfMonth(currentDate, dayOfMonth);
|
addMonthToDayOfMonth(currentDate, dayOfMonth, monthInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (params.get("BYSETPOS") != null)
|
else if (params.get("BYSETPOS") != null)
|
||||||
@@ -403,7 +403,7 @@ public class CalendarRecurrenceHelper
|
|||||||
if (currentDate.get(Calendar.DAY_OF_MONTH) > 8)
|
if (currentDate.get(Calendar.DAY_OF_MONTH) > 8)
|
||||||
{
|
{
|
||||||
// Move to start, in next month
|
// Move to start, in next month
|
||||||
addMonthToFirstDayOfWeek(currentDate, dayOfWeek);
|
addMonthToFirstDayOfWeek(currentDate, dayOfWeek, monthInterval);
|
||||||
}
|
}
|
||||||
else if (currentDate.get(Calendar.DAY_OF_WEEK) != dayOfWeek)
|
else if (currentDate.get(Calendar.DAY_OF_WEEK) != dayOfWeek)
|
||||||
{
|
{
|
||||||
@@ -418,7 +418,7 @@ public class CalendarRecurrenceHelper
|
|||||||
|
|
||||||
while (currentDate.getTime().before(onOrAfter))
|
while (currentDate.getTime().before(onOrAfter))
|
||||||
{
|
{
|
||||||
addMonthToFirstDayOfWeek(currentDate, dayOfWeek);
|
addMonthToFirstDayOfWeek(currentDate, dayOfWeek, monthInterval);
|
||||||
}
|
}
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -436,7 +436,7 @@ public class CalendarRecurrenceHelper
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
addMonthToFirstDayOfWeek(currentDate, dayOfWeek);
|
addMonthToFirstDayOfWeek(currentDate, dayOfWeek, monthInterval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,14 +457,14 @@ public class CalendarRecurrenceHelper
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentDate.set(Calendar.YEAR, currentDate.get(Calendar.YEAR) + 1);
|
currentDate.set(Calendar.YEAR, currentDate.get(Calendar.YEAR) + interval);
|
||||||
currentDate.set(Calendar.MONTH, month);
|
currentDate.set(Calendar.MONTH, month);
|
||||||
currentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
currentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (currentDate.getTime().before(onOrAfter))
|
while (currentDate.getTime().before(onOrAfter))
|
||||||
{
|
{
|
||||||
currentDate.set(Calendar.YEAR, currentDate.get(Calendar.YEAR) + 1);
|
currentDate.set(Calendar.YEAR, currentDate.get(Calendar.YEAR) + interval);
|
||||||
currentDate.set(Calendar.MONTH, month);
|
currentDate.set(Calendar.MONTH, month);
|
||||||
currentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
currentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||||
}
|
}
|
||||||
@@ -484,7 +484,7 @@ public class CalendarRecurrenceHelper
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentDate.set(Calendar.YEAR, currentDate.get(Calendar.YEAR) + 1);
|
currentDate.set(Calendar.YEAR, currentDate.get(Calendar.YEAR) + interval);
|
||||||
currentDate.set(Calendar.MONTH, month);
|
currentDate.set(Calendar.MONTH, month);
|
||||||
currentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
currentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||||
}
|
}
|
||||||
@@ -497,20 +497,23 @@ public class CalendarRecurrenceHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addMonthToDayOfMonth(Calendar c, int dayOfMonth)
|
private static void addMonthToDayOfMonth(Calendar c, int dayOfMonth, int monthInterval)
|
||||||
{
|
{
|
||||||
// Set it to the 1st
|
for (int i=0; i<monthInterval; i++)
|
||||||
c.set(Calendar.DAY_OF_MONTH, 1);
|
{
|
||||||
// Add 33 days, will be on the 2nd-6th
|
// Set it to the 1st
|
||||||
c.add(Calendar.DATE, 33);
|
c.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
// Set to the requred day in the month
|
// Add 33 days, will be on the 2nd-6th
|
||||||
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
c.add(Calendar.DATE, 33);
|
||||||
|
// Set to the requred day in the month
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addMonthToFirstDayOfWeek(Calendar c, int dayOfWeek)
|
private static void addMonthToFirstDayOfWeek(Calendar c, int dayOfWeek, int monthInterval)
|
||||||
{
|
{
|
||||||
// Go forward to the 1st of next month
|
// Go forward to the 1st of next month
|
||||||
addMonthToDayOfMonth(c, 1);
|
addMonthToDayOfMonth(c, 1, monthInterval);
|
||||||
|
|
||||||
// Set the day of the week
|
// Set the day of the week
|
||||||
Date t = c.getTime();
|
Date t = c.getTime();
|
||||||
|
Reference in New Issue
Block a user