Defect #29855 » 0001-Fix-add_working_days-returning-a-date-one-working-da.patch
| lib/redmine/utils/date_calculation.rb | ||
|---|---|---|
| 84 | 84 |
# Adds working days to the given date, |
| 85 | 85 |
# taking only non working week days into account |
| 86 | 86 |
def add_working_week_days(date, working_days) |
| 87 |
weeks = working_days / (7 - non_working_week_days.size) |
|
| 87 |
# Advance by whole weeks first. This lands on the same week day as |
|
| 88 |
# date, so it is a non-working day if date is a non-working day. |
|
| 89 |
# Subtracting 1 prevents days_left from being 0 when working_days is |
|
| 90 |
# a multiple of the working days per week, so the remainder loop |
|
| 91 |
# below always runs and the result ends on the last working day it |
|
| 92 |
# counts. |
|
| 93 |
weeks = (working_days - 1) / (7 - non_working_week_days.size) |
|
| 88 | 94 |
result = weeks * 7 |
| 95 |
# Remainder loop: advance day by day until the remaining working days |
|
| 96 |
# are counted |
|
| 89 | 97 |
days_left = working_days - weeks * (7 - non_working_week_days.size) |
| 90 | 98 |
cwday = date.cwday |
| 91 | 99 |
while days_left > 0 |
| test/unit/lib/redmine/utils/date_calculation_test.rb | ||
|---|---|---|
| 65 | 65 |
assert_add_working_days '2012-10-31', '2012-10-10', 15 |
| 66 | 66 |
assert_add_working_days '2012-10-19', '2012-10-09', 8 |
| 67 | 67 |
assert_add_working_days '2012-10-23', '2012-10-11', 8 |
| 68 |
# From Saturday and Sunday to the 5th working day, Friday 2012-10-26 |
|
| 69 |
assert_add_working_days '2012-10-26', '2012-10-20', 5 |
|
| 70 |
assert_add_working_days '2012-10-26', '2012-10-21', 5 |
|
| 68 | 71 |
end |
| 69 | 72 |
end |