diff --git a/lib/redmine/utils.rb b/lib/redmine/utils.rb index d255dfa916..fb487a7996 100644 --- a/lib/redmine/utils.rb +++ b/lib/redmine/utils.rb @@ -106,22 +106,10 @@ module Redmine # Adds working days to the given date def add_working_days(date, working_days) - if working_days > 0 - weeks = working_days / (7 - non_working_week_days.size) - result = weeks * 7 - days_left = working_days - weeks * (7 - non_working_week_days.size) - cwday = date.cwday - while days_left > 0 - cwday += 1 - unless non_working_week_days.include?(((cwday - 1) % 7) + 1) - days_left -= 1 - end - result += 1 - end - next_working_date(date + result) - else - date + working_days.times do + date = next_working_date(date + 1) end + date end # Returns the date of the first day on or after the given date that is a working day diff --git a/test/unit/lib/redmine/utils/date_calculation.rb b/test/unit/lib/redmine/utils/date_calculation.rb index 4228486787..80076df56d 100644 --- a/test/unit/lib/redmine/utils/date_calculation.rb +++ b/test/unit/lib/redmine/utils/date_calculation.rb @@ -63,6 +63,8 @@ class Redmine::Utils::DateCalculationTest < ActiveSupport::TestCase assert_add_working_days '2012-10-31', '2012-10-10', 15 assert_add_working_days '2012-10-19', '2012-10-09', 8 assert_add_working_days '2012-10-23', '2012-10-11', 8 + assert_add_working_days '2012-10-26', '2012-10-20', 5 + assert_add_working_days '2012-10-26', '2012-10-21', 5 end end