Project

General

Profile

Defect #29855 ยป fix-29855.patch

Mizuki ISHIKAWA, 2018-11-07 07:48

View differences:

lib/redmine/utils.rb
106 106

  
107 107
      # Adds working days to the given date
108 108
      def add_working_days(date, working_days)
109
        if working_days > 0
110
          weeks = working_days / (7 - non_working_week_days.size)
111
          result = weeks * 7
112
          days_left = working_days - weeks * (7 - non_working_week_days.size)
113
          cwday = date.cwday
114
          while days_left > 0
115
            cwday += 1
116
            unless non_working_week_days.include?(((cwday - 1) % 7) + 1)
117
              days_left -= 1
118
            end
119
            result += 1
120
          end
121
          next_working_date(date + result)
122
        else
123
          date
109
        working_days.times do
110
          date = next_working_date(date + 1)
124 111
        end
112
        date
125 113
      end
126 114

  
127 115
      # 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
63 63
      assert_add_working_days '2012-10-31', '2012-10-10', 15
64 64
      assert_add_working_days '2012-10-19', '2012-10-09', 8
65 65
      assert_add_working_days '2012-10-23', '2012-10-11', 8
66
      assert_add_working_days '2012-10-26', '2012-10-20', 5
67
      assert_add_working_days '2012-10-26', '2012-10-21', 5
66 68
    end
67 69
  end
68 70

  
    (1-1/1)