【发布时间】:2015-07-16 01:07:36
【问题描述】:
我正在为每周重复使用定期约会功能。我有一个开始日期、结束日期、重复开始日期、重复结束日期和选定的日期(周一、周二、周三、周四...周日)
这是一个例子
Start Date: 15th July 2015
End Date: 18th July 2015
Recurrence Start Date: 20th July 2015
Recurrence End Date: 20th August 2015
Recurrence frequency = weekly
Selected Days(Array storing int values for days_of_week with Sun as 1 and Sat as 7) = Mon, Wed, Sun
根据要求,我需要创建这样的约会:-
Appointment 1 - 20th July 2015 (Mon) - 23rd July 2015(Thu)
............Appointment 2 - 22nd July 2015 (Wed) - 25th July 2015(Sat)
............Appointment 3 - 26th July 2015 (Sun) - 29th July 2015(Wed)
............Appointment 4 - 27th July 2015 (Mon) - 30th July 2015(Thu)
但正如您所见,我需要防止出现重叠。我试图开发一种算法来防止这种重叠,而实际上并不知道实际的日子。
所以基本上没有区别。开始日期和结束日期之间的天数必须大于数组的两个连续索引之间的差。
我遇到了问题,因为Sun - Wed ( 1 - 4) 会给我一个负数,所以比较会小于结束日期和开始日期( end date - start date) 之间的天数差。
这是我到目前为止所做的:-
Calendar e = Calendar.getInstance();
Calendar f = Calendar.getInstance();
e.setTime(sStartDate);
f.setTime(estSignIn);
long diffInDays = ((estSignIn.getTime() - sStartDate.getTime())
/ (1000 * 60 * 60 * 24) );
for(int j=0; j < localSelectedDays.length - 1 ; j++)
{
e.set(Calendar.DAY_OF_WEEK, localSelectedDays[j]);
f.set(Calendar.DAY_OF_WEEK, localSelectedDays[j +1]);
int x = e.get(Calendar.DAY_OF_WEEK);
int y = f.get(Calendar.DAY_OF_WEEK);
if ((y - x) <= diffInDays)
{
System.out.println("ERROR" + "Y:" + y + "x" + x);
}
}
【问题讨论】:
-
你在问什么?你们约会之间有什么关系?你自己尝试过什么,你在哪里卡住了?