Project

General

Profile

Defect #29855 » 0001-Fix-add_working_days-returning-a-date-one-working-da.patch

Go MAEDA, 2026-10-14 10:18

View differences:

lib/redmine/utils/date_calculation.rb
# Adds working days to the given date,
# taking only non working week days into account
def add_working_week_days(date, working_days)
weeks = working_days / (7 - non_working_week_days.size)
# Advance by whole weeks first. This lands on the same week day as
# date, so it is a non-working day if date is a non-working day.
# Subtracting 1 prevents days_left from being 0 when working_days is
# a multiple of the working days per week, so the remainder loop
# below always runs and the result ends on the last working day it
# counts.
weeks = (working_days - 1) / (7 - non_working_week_days.size)
result = weeks * 7
# Remainder loop: advance day by day until the remaining working days
# are counted
days_left = working_days - weeks * (7 - non_working_week_days.size)
cwday = date.cwday
while days_left > 0
test/unit/lib/redmine/utils/date_calculation_test.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
# From Saturday and Sunday to the 5th working day, Friday 2012-10-26
assert_add_working_days '2012-10-26', '2012-10-20', 5
assert_add_working_days '2012-10-26', '2012-10-21', 5
end
end
(2-2/3)