fix for repeat-after-complete weekly setting due time on tasks

pull/14/head
Tim Su 13 years ago
parent 40971ccd19
commit 438bfdefa4

@ -46,31 +46,10 @@ public class DateUtilities {
* @return the calculated time in milliseconds
*/
public static final long addCalendarMonthsToUnixtime(long time, int interval) {
long result = 0;
Date date = new Date(time);
int month = date.getMonth();
int year = date.getYear();
int yearsToAdd = interval / 12;
int monthsToAdd = interval % 12;
year += yearsToAdd;
month += monthsToAdd;
// correct month overflow
if (month > Calendar.DECEMBER) {
month = month - Calendar.DECEMBER - 1;
year++;
}
// the day stays the same, thats the point
// it's especially important for birthday-reminders
date.setMonth(month);
date.setYear(year);
result = date.getTime();
return result;
Calendar c = Calendar.getInstance();
c.setTimeInMillis(time);
c.add(Calendar.MONTH, interval);
return c.getTimeInMillis();
}
/** Returns unixtime for current time */

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timsu.astrid"
android:versionName="3.8.4"
android:versionCode="195">
android:versionName="3.8.4.1"
android:versionCode="196">
<!-- widgets, alarms, and services will break if Astrid is installed on SD card -->
<!-- android:installLocation="internalOnly"> -->

@ -97,8 +97,9 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
clone.setValue(Task.REMINDER_SNOOZE, 0L);
clone.setValue(Task.REMINDER_LAST, 0L);
boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null &&
!Preferences.getStringValue(R.string.gcal_p_default).equals("-1");
boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null
&& !Preferences.getStringValue(R.string.gcal_p_default).
equals("-1"); //$NON-NLS-1$
if (gcalCreateEventEnabled) {
ContentResolver cr = ContextManager.getContext().getContentResolver();
Uri calendarUri = GCalHelper.createTaskEvent(clone, cr, new ContentValues());
@ -139,13 +140,14 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
if(rrule.getFreq() == Frequency.HOURLY || rrule.getFreq() == Frequency.MINUTELY)
return handleSubdayRepeat(original, rrule);
else if(rrule.getByDay().size() > 0 && repeatAfterCompletion)
return handleWeeklyRepeatAfterComplete(rrule, original);
else if(rrule.getFreq() == Frequency.WEEKLY && rrule.getByDay().size() > 0 && repeatAfterCompletion)
return handleWeeklyRepeatAfterComplete(rrule, original, task.hasDueTime());
else
return invokeRecurrence(rrule, original, startDateAsDV);
}
private static long handleWeeklyRepeatAfterComplete(RRule rrule, Date original) {
private static long handleWeeklyRepeatAfterComplete(RRule rrule, Date original,
boolean hasDueTime) {
List<WeekdayNum> byDay = rrule.getByDay();
long newDate = original.getTime();
newDate += DateUtilities.ONE_WEEK * (rrule.getInterval() - 1);
@ -158,7 +160,12 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
do {
date.add(Calendar.DATE, 1);
} while (date.get(Calendar.DAY_OF_WEEK) != next.wday.javaDayNum);
return date.getTimeInMillis();
long time = date.getTimeInMillis();
if(hasDueTime)
return Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, time);
else
return Task.createDueDate(Task.URGENCY_SPECIFIC_DAY, time);
}
private static Comparator<WeekdayNum> weekdayCompare = new Comparator<WeekdayNum>() {

@ -114,7 +114,8 @@ public class NewRepeatTests<REMOTE_MODEL> extends DatabaseTestCase {
}
}
protected void testRepeating(boolean completeBefore, boolean fromCompletion, RRule rrule, Frequency frequency, String title) {
protected void testRepeating(boolean completeBefore, boolean fromCompletion,
RRule rrule, Frequency frequency, String title) {
for (int i = 0; i < StartupService.INTRO_TASK_SIZE; i++) { // Create startup tasks so sync services don't miss the test tasks
Task temp = new Task();
temp.setValue(Task.TITLE, "" + i);

@ -50,11 +50,15 @@ public class RepeatAfterCompleteTests extends TodorooTestCase {
buildRRule(6, freq);
nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
assertDateTimeEquals(freq.toString() + "x6", DateUtilities.now() + 6 * interval, nextDueDate);
task.setValue(Task.DUE_DATE, nextDueDate);
assertTrue(task.hasDueTime());
}
}
public void testDailyAndGreaterFreqs() throws ParseException {
task.setValue(Task.DUE_DATE, DateUtilities.now() - DateUtilities.ONE_WEEK);
task.setValue(Task.DUE_DATE,
Task.createDueDate(Task.URGENCY_SPECIFIC_DAY,
DateUtilities.now() - DateUtilities.ONE_WEEK));
task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);
for(int interval = 1; interval < 7; interval++) {
@ -76,6 +80,8 @@ public class RepeatAfterCompleteTests extends TodorooTestCase {
buildRRule(interval, freq);
nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
assertDateEquals(freq.toString() + "x" + interval, next, nextDueDate);
task.setValue(Task.DUE_DATE, nextDueDate);
assertFalse(task.hasDueTime());
}
}
}

Loading…
Cancel
Save