Fix for repeat-after-completing not triggering the correct date (bug with rfc2445 library)

pull/14/head
Tim Su 14 years ago
parent 8a0b6f1a61
commit 24a764f682

@ -10,13 +10,13 @@
<classpathentry exported="true" kind="lib" path="libs/annotations.jar"/>
<classpathentry exported="true" kind="lib" path="libs/commons-codec-1.3.jar"/>
<classpathentry exported="true" kind="lib" path="libs/jsr305.jar"/>
<classpathentry exported="true" kind="lib" path="libs/rfc2445-no-joda.jar"/>
<classpathentry exported="true" kind="lib" path="libs/locale_platform.jar"/>
<classpathentry exported="true" kind="lib" path="libs/todoroo-g.jar"/>
<classpathentry kind="lib" path="libs/framework.jar"/>
<classpathentry kind="lib" path="libs/httpmime-4.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/framework.jar"/>
<classpathentry exported="true" kind="lib" path="libs/httpmime-4.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="libs/rfc2445-4Mar2011.jar"/>
<classpathentry kind="src" path="GreenDroid_src"/>
<classpathentry kind="src" path="astridApi_src"/>
<classpathentry kind="src" path="facebook_src"/>
<classpathentry kind="src" path="GreenDroid_src"/>
<classpathentry kind="output" path="ecbuild"/>
</classpath>

Binary file not shown.

@ -68,7 +68,6 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
clone.setValue(Task.COMPLETION_DATE, 0L);
clone.setValue(Task.TIMER_START, 0L);
clone.setValue(Task.ELAPSED_SECONDS, 0);
// Fix for 13186799: clear snooze from old task
clone.setValue(Task.REMINDER_SNOOZE, 0L);
PluginServices.getTaskService().save(clone);
@ -104,14 +103,15 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
repeatFrom = today;
}
} else if (task.hasDueDate() && repeatAfterCompletion) {
repeatFromDate = new Date(task.getValue(Task.DUE_DATE));
if(task.hasDueTime()) {
repeatFromDate = new Date(task.getValue(Task.DUE_DATE));
repeatFrom = new DateTimeValueImpl(today.year(),
today.month(), today.day(),
repeatFromDate.getHours(), repeatFromDate.getMinutes(), repeatFromDate.getSeconds());
} else {
repeatFrom = today;
}
repeatFromDate = new Date();
} else {
repeatFrom = today;
}
@ -161,9 +161,15 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
nextDate.day()).getTime());
}
if(newDueDate > DateUtilities.now() && (repeatAfterCompletion || (newDueDate != repeatFromDate.getTime())))
break;
// detect if we finished
if(newDueDate > DateUtilities.now()) {
// if byDay is set and interval > 1, we need to run again
if(rrule.getByDay().size() > 0 && rrule.getInterval() > 0) {
if(newDueDate - repeatFromDate.getTime() > DateUtilities.ONE_WEEK)
break;
} else if(newDueDate > repeatFromDate.getTime())
break;
}
}
}

@ -24,6 +24,9 @@ public class StatisticsService {
if(dontCollectStatistics())
return;
if(localyticsSession != null)
return;
localyticsSession = new LocalyticsSession(context.getApplicationContext(),
Constants.LOCALYTICS_KEY);
localyticsSession.open();
@ -39,14 +42,19 @@ public class StatisticsService {
if(dontCollectStatistics())
return;
localyticsSession.upload();
if(localyticsSession != null)
localyticsSession.upload();
}
/**
* Indicate session was paused
*/
public static void sessionPause() {
localyticsSession.close();
if(dontCollectStatistics())
return;
if(localyticsSession != null)
localyticsSession.close();
}
/**
@ -67,7 +75,8 @@ public class StatisticsService {
if(dontCollectStatistics())
return;
localyticsSession.tagEvent(event);
if(localyticsSession != null)
localyticsSession.tagEvent(event);
}
private static boolean dontCollectStatistics() {

@ -1,10 +1,13 @@
package com.todoroo.astrid.repeats;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
import com.google.ical.values.Weekday;
import com.google.ical.values.WeekdayNum;
import com.todoroo.andlib.test.TodorooTestCase;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
@ -61,5 +64,28 @@ public class AdvancedRepeatTests extends TodorooTestCase {
assertNotSame(nextDueDate, evenMoreNextDueDate);
}
/** test alternate completion flag */
public void testAfterCompleteMultipleWeeks() throws Exception {
// create a weekly task due a couple days in the past, but with the 'after completion'
// specified. should be due 7 days from now
Task task = new Task();
long originalDueDate = (DateUtilities.now() - 1 * DateUtilities.ONE_DAY) / 1000L * 1000L;
task.setValue(Task.DUE_DATE, task.createDueDate(Task.URGENCY_SPECIFIC_DAY, originalDueDate));
task.setFlag(Task.FLAGS, Task.FLAG_REPEAT_AFTER_COMPLETION, true);
RRule rrule = new RRule();
rrule.setInterval(5);
rrule.setFreq(Frequency.WEEKLY);
for(Weekday day : Weekday.values()) {
ArrayList<WeekdayNum> days = new ArrayList<WeekdayNum>();
days.add(new WeekdayNum(0, day));
rrule.setByDay(days);
long nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
assertTrue("Due date is '" + new Date(nextDueDate) + "', expected more like '" +
new Date(DateUtilities.now() + 5 * DateUtilities.ONE_WEEK) + "'",
Math.abs(nextDueDate - DateUtilities.now() - 5 * DateUtilities.ONE_WEEK) < DateUtilities.ONE_WEEK);
}
}
}

Loading…
Cancel
Save