Project

General

Profile

Defect #29855 » fix-29855.patch

Mizuki ISHIKAWA, 2018-11-07 07:48

View differences:

lib/redmine/utils.rb
# 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
test/unit/lib/redmine/utils/date_calculation.rb
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
(1-1/3)