diff --git a/app/models/recurring_todos/daily_repeat_pattern.rb b/app/models/recurring_todos/daily_repeat_pattern.rb index 4e94da55..17dd00f0 100644 --- a/app/models/recurring_todos/daily_repeat_pattern.rb +++ b/app/models/recurring_todos/daily_repeat_pattern.rb @@ -18,7 +18,7 @@ module RecurringTodos if only_work_days? I18n.t("todos.recurrence.pattern.on_work_days") elsif every_x_days > 1 - I18n.t("todos.recurrence.pattern.every_n", :n => every_x_days) + " " + I18n.t("common.days_midsentence.other") + I18n.t("todos.recurrence.pattern.every_n_days", :n => every_x_days) else I18n.t("todos.recurrence.pattern.every_day") end @@ -37,10 +37,11 @@ module RecurringTodos start = determine_start(previous, 1.day) if only_work_days? + # jump over weekend if necessary return start + 2.day if start.wday() == 6 # saturday return start + 1.day if start.wday() == 0 # sunday return start - else # every nth day; n = every_other1 + else # if there was no previous todo, do not add n: the first todo starts on # today or on start_from return previous == nil ? start : start+every_x_days.day-1.day diff --git a/config/locales/en.yml b/config/locales/en.yml index e68c3a90..90e9970d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -623,13 +623,14 @@ en: - December third: third every_n: every %{n} + every_n_days: every %{n} days + every_day: every day on_day_n: on day %{n} second: second every_xth_day_of_every_n_months: every %{x} %{day} of every %{n_months} from: from weekly: weekly last: last - every_day: every day the_xth_day_of_month: the %{x} %{day} of %{month} times: for %{number} times on_work_days: on work days diff --git a/test/models/recurring_todos/daily_repeat_pattern_test.rb b/test/models/recurring_todos/daily_repeat_pattern_test.rb index 89a6348e..edfd4977 100644 --- a/test/models/recurring_todos/daily_repeat_pattern_test.rb +++ b/test/models/recurring_todos/daily_repeat_pattern_test.rb @@ -62,11 +62,18 @@ module RecurringTodos assert_equal @today+14.days, due_date end - def test_daily_work_days - assert_equal @monday, @every_workday.get_due_date(@friday) - assert_equal @monday, @every_workday.get_due_date(@saturday) - assert_equal @monday, @every_workday.get_due_date(@sunday) - assert_equal @tuesday, @every_workday.get_due_date(@monday) + def test_only_work_days_skips_weekend + assert_equal @tuesday, @every_workday.get_due_date(@monday), "should select next day if it is not in weekend" + + assert_equal @monday, @every_workday.get_due_date(@friday), "should select monday if it is in weekend" + assert_equal @monday, @every_workday.get_due_date(@saturday), "should select monday if it is in weekend" + assert_equal @monday, @every_workday.get_due_date(@sunday), "should select monday if it is in weekend" + end + + def test_every_x_days + assert_equal @tuesday, @every_day.get_due_date(@monday), "should select next day in middle week" + assert_equal @saturday, @every_day.get_due_date(@friday), "should select next day at end of week" + assert_equal @sunday, @every_day.get_due_date(@saturday), "should select next day in weekend" end end