Skip to content

Commit

Permalink
Fix #509 by using GregorianCalendar to reschedule repeating remindes …
Browse files Browse the repository at this point in the history
…so that they handle the switch between DST and ST
  • Loading branch information
CampelloManuel committed May 1, 2024
1 parent 8aeb082 commit 8cf86e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,40 +211,42 @@ synchronized public int update(@NonNull Uri uri, ContentValues values,
updateUris.add(TaskList.URI);
updateUris.add(TaskList.URI_WITH_COUNT);
// Batch. No checks made
result += db.update(Task.TABLE_NAME, values, selection,
selectionArgs);
result += db.update(Task.TABLE_NAME, values, selection, selectionArgs);
break;
case Notification.BASEITEMCODE:
case Notification.WITHTASKQUERYITEMCODE:
updateUris.add(Notification.URI);
updateUris.add(Notification.URI_WITH_TASK_PATH);
// final Notification n = new Notification(uri, values);
result += db.update(Notification.TABLE_NAME, values,
Notification.whereIdIs(selection), Notification
.whereIdArg(Long.parseLong(uri
.getLastPathSegment()), selectionArgs));
result += db.update(
Notification.TABLE_NAME,
values,
Notification.whereIdIs(selection),
Notification.whereIdArg(
Long.parseLong(uri.getLastPathSegment()), selectionArgs));
break;
case Notification.BASEURICODE:
updateUris.add(Notification.URI);
updateUris.add(Notification.URI_WITH_TASK_PATH);
// No checks
result += db.update(Notification.TABLE_NAME, values, selection,
selectionArgs);
result += db.update(Notification.TABLE_NAME, values, selection, selectionArgs);
break;
case RemoteTaskList.BASEITEMCODE:
updateUris.add(RemoteTaskList.URI);
result += db.update(RemoteTaskList.TABLE_NAME, values,
RemoteTaskList.whereIdIs(selection),
RemoteTaskList.whereIdArg(Long.parseLong(uri
.getLastPathSegment()), selectionArgs)
RemoteTaskList.whereIdArg(
Long.parseLong(uri.getLastPathSegment()), selectionArgs)
);
break;
case RemoteTask.BASEITEMCODE:
updateUris.add(RemoteTask.URI);
result += db.update(RemoteTask.TABLE_NAME, values,
result += db.update(
RemoteTask.TABLE_NAME,
values,
RemoteTask.whereIdIs(selection),
RemoteTask.whereIdArg(Long.parseLong(uri
.getLastPathSegment()), selectionArgs)
RemoteTask.whereIdArg(
Long.parseLong(uri.getLastPathSegment()), selectionArgs)
);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ public ContentValues getContent() {
values.put(Columns.RADIUS, radius);

return values;

}

@Override
Expand Down Expand Up @@ -613,11 +612,15 @@ public void deleteOrReschedule(final Context context) {
// For example if this function runs at "now" = 19:30 to reschedule a reminder that was
// planned for "base" = 19:15, then "now" is > "base", therefore start = 1
final int start = now < base ? 0 : 1;
final long oneDay = 24 * 60 * 60 * 1000; // = 1 day, in milliseconds
boolean done = false;
for (int i = start; i <= 7; i++) {
gcToSchedule.setTimeInMillis(base + i * oneDay);
if (i!=0) {
// add a day to the hypotized new due date.
// It automatically handles the transitions between ST and DST
gcToSchedule.add(Calendar.DAY_OF_MONTH, 1);
}

// check if the reminder should repeat on this day
if (repeatsOn(gcToSchedule.get(GregorianCalendar.DAY_OF_WEEK))) {
// we found the 1° day in which the reminder needs to repeat: save that as the
// new "due time" in the database, and we're done.
Expand Down

0 comments on commit 8cf86e4

Please sign in to comment.