From 7b90c00d849993c4083910d23ac15ee3fa01d7b6 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 6 Oct 2008 11:11:56 +0200 Subject: [PATCH] fix corner case where checking repeating todos complete that are due todo today will create a new todo that is also due today with the intriduction of datetime for due and show_from, the time part needed to be discarded in a compare also adding some comments to be able to understand the code better --- app/controllers/todos_controller.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index ff4a108d..ada43168 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -776,10 +776,24 @@ class TodosController < ApplicationController @recurring_todo = nil if @todo.from_recurring_todo? @recurring_todo = current_user.recurring_todos.find(@todo.recurring_todo_id) + + # check for next todo either from the due date or the show_from date date_to_check = @todo.due.nil? ? @todo.show_from : @todo.due + + # if both due and show_from are nil, check for a next todo with yesterday + # as reference point. We pick yesterday so that new todos for today will + # be created instead of new todos for tomorrow. date_to_check = Time.zone.now-1.day if date_to_check.nil? + if @recurring_todo.active? && @recurring_todo.has_next_todo(date_to_check) - date = date_to_check >= Time.zone.now ? date_to_check : Time.zone.now-1.day + + # shift the reference date to yesterday if date_to_check is furher in + # the past. This is to make sure we do not get older todos for overdue + # todos. I.e. checking a daily todo that is overdue with 5 days will + # create a new todo which is overdue by 4 days if we don't shift the + # date. Discard the time part in the compare + date = date_to_check.at_midnight >= Time.zone.now.at_midnight ? date_to_check : Time.zone.now-1.day + @new_recurring_todo = create_todo_from_recurring_todo(@recurring_todo, date) end end