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

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

@ -46,31 +46,10 @@ public class DateUtilities {
* @return the calculated time in milliseconds * @return the calculated time in milliseconds
*/ */
public static final long addCalendarMonthsToUnixtime(long time, int interval) { public static final long addCalendarMonthsToUnixtime(long time, int interval) {
long result = 0; Calendar c = Calendar.getInstance();
Date date = new Date(time); c.setTimeInMillis(time);
c.add(Calendar.MONTH, interval);
int month = date.getMonth(); return c.getTimeInMillis();
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;
} }
/** Returns unixtime for current time */ /** Returns unixtime for current time */

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

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

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

Loading…
Cancel
Save