To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 28 / 287ad425b706a1e849a16749d3a013cf82f1d342.svn-base @ 1298:4f746d8966dd
History | View | Annotate | Download (3.19 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License |
| 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 |
# of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
require File.expand_path('../../../../../test_helper', __FILE__)
|
| 19 |
|
| 20 |
class Redmine::Utils::DateCalculationTest < ActiveSupport::TestCase |
| 21 |
include Redmine::Utils::DateCalculation |
| 22 |
|
| 23 |
def test_working_days_without_non_working_week_days |
| 24 |
with_settings :non_working_week_days => [] do |
| 25 |
assert_working_days 18, '2012-10-09', '2012-10-27' |
| 26 |
assert_working_days 6, '2012-10-09', '2012-10-15' |
| 27 |
assert_working_days 5, '2012-10-09', '2012-10-14' |
| 28 |
assert_working_days 3, '2012-10-09', '2012-10-12' |
| 29 |
assert_working_days 3, '2012-10-14', '2012-10-17' |
| 30 |
assert_working_days 16, '2012-10-14', '2012-10-30' |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
def test_working_days_with_non_working_week_days |
| 35 |
with_settings :non_working_week_days => %w(6 7) do |
| 36 |
assert_working_days 14, '2012-10-09', '2012-10-27' |
| 37 |
assert_working_days 4, '2012-10-09', '2012-10-15' |
| 38 |
assert_working_days 4, '2012-10-09', '2012-10-14' |
| 39 |
assert_working_days 3, '2012-10-09', '2012-10-12' |
| 40 |
assert_working_days 8, '2012-10-09', '2012-10-19' |
| 41 |
assert_working_days 8, '2012-10-11', '2012-10-23' |
| 42 |
assert_working_days 2, '2012-10-14', '2012-10-17' |
| 43 |
assert_working_days 11, '2012-10-14', '2012-10-30' |
| 44 |
end |
| 45 |
end |
| 46 |
|
| 47 |
def test_add_working_days_without_non_working_week_days |
| 48 |
with_settings :non_working_week_days => [] do |
| 49 |
assert_add_working_days '2012-10-10', '2012-10-10', 0 |
| 50 |
assert_add_working_days '2012-10-11', '2012-10-10', 1 |
| 51 |
assert_add_working_days '2012-10-12', '2012-10-10', 2 |
| 52 |
assert_add_working_days '2012-10-13', '2012-10-10', 3 |
| 53 |
assert_add_working_days '2012-10-25', '2012-10-10', 15 |
| 54 |
end |
| 55 |
end |
| 56 |
|
| 57 |
def test_add_working_days_with_non_working_week_days |
| 58 |
with_settings :non_working_week_days => %w(6 7) do |
| 59 |
assert_add_working_days '2012-10-10', '2012-10-10', 0 |
| 60 |
assert_add_working_days '2012-10-11', '2012-10-10', 1 |
| 61 |
assert_add_working_days '2012-10-12', '2012-10-10', 2 |
| 62 |
assert_add_working_days '2012-10-15', '2012-10-10', 3 |
| 63 |
assert_add_working_days '2012-10-31', '2012-10-10', 15 |
| 64 |
assert_add_working_days '2012-10-19', '2012-10-09', 8 |
| 65 |
assert_add_working_days '2012-10-23', '2012-10-11', 8 |
| 66 |
end |
| 67 |
end |
| 68 |
|
| 69 |
def assert_working_days(expected_days, from, to) |
| 70 |
assert_equal expected_days, working_days(from.to_date, to.to_date) |
| 71 |
end |
| 72 |
|
| 73 |
def assert_add_working_days(expected_date, from, working_days) |
| 74 |
assert_equal expected_date.to_date, add_working_days(from.to_date, working_days) |
| 75 |
end |
| 76 |
end |