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