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
This commit is contained in:
Reinier Balt 2008-10-06 11:11:56 +02:00
parent 89043af7ff
commit 7b90c00d84

View file

@ -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