-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathtest_business_days_date.rb
More file actions
189 lines (165 loc) · 7.42 KB
/
Copy pathtest_business_days_date.rb
File metadata and controls
189 lines (165 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
require 'helper'
describe "business days" do
describe "with a standard Date object" do
describe "when adding/subtracting positive number of business days" do
it "move to tomorrow if we add a business day" do
first = Date.parse("April 13th, 2010")
later = 1.business_day.after(first)
expected = Date.parse("April 14th, 2010")
assert_equal expected, later
end
it "move to yesterday is we subtract a business day" do
first = Date.parse("April 13th, 2010")
before = 1.business_day.before(first)
expected = Date.parse("April 12th, 2010")
assert_equal expected, before
end
it "take into account the weekend when adding a day" do
first = Date.parse("April 9th, 2010")
after = 1.business_day.after(first)
expected = Date.parse("April 12th, 2010")
assert_equal expected, after
end
it "take into account the weekend when subtracting a day" do
first = Date.parse("April 12th, 2010")
before = 1.business_day.before(first)
expected = Date.parse("April 9th, 2010")
assert_equal expected, before
end
it "move forward one week when adding 5 business days" do
first = Date.parse("April 9th, 2010")
after = 5.business_days.after(first)
expected = Date.parse("April 16th, 2010")
assert_equal expected, after
end
it "move backward one week when subtracting 5 business days" do
first = Date.parse("April 16th, 2010")
before = 5.business_days.before(first)
expected = Date.parse("April 9th, 2010")
assert_equal expected, before
end
it "take into account a holiday when adding a day" do
three_day_weekend = Date.parse("July 5th, 2010")
BusinessTime::Config.holidays << three_day_weekend
friday_afternoon = Date.parse("July 2nd, 2010")
tuesday_afternoon = 1.business_day.after(friday_afternoon)
expected = Date.parse("July 6th, 2010")
assert_equal expected, tuesday_afternoon
end
it "take into account a holiday on a weekend" do
july_4 = Date.parse("July 4th, 2010")
BusinessTime::Config.holidays << july_4
friday_afternoon = Date.parse("July 2nd, 2010")
monday_afternoon = 1.business_day.after(friday_afternoon)
expected = Date.parse("July 5th, 2010")
assert_equal expected, monday_afternoon
end
it "move to Monday if we add one business day during a weekend" do
saturday = Date.parse("April 10th, 2010")
later = 1.business_days.after(saturday)
expected = Date.parse("April 12th, 2010")
assert_equal expected, later
end
it "move to thursday if we subtract one business day during a weekend" do
saturday = Date.parse("April 10th, 2010")
before = 1.business_days.before(saturday)
expected = Date.parse("April 8th, 2010")
assert_equal expected, before
end
end
describe "when adding/subtracting negative number of business days" do
it "move to yesterday if we add a negative business day" do
first = Date.parse("April 13th, 2010")
before = -1.business_day.after(first)
expected = Date.parse("April 12th, 2010")
assert_equal expected, before
end
it "move to tomorrow is we subtract a negative business day" do
first = Date.parse("April 13th, 2010")
after = -1.business_day.before(first)
expected = Date.parse("April 14th, 2010")
assert_equal expected, after
end
it "take into account the weekend when adding a negative day" do
first = Date.parse("April 12th, 2010")
before = -1.business_day.after(first)
expected = Date.parse("April 9th, 2010")
assert_equal expected, before
end
it "take into account the weekend when subtracting a negative day" do
first = Date.parse("April 9th, 2010")
after = -1.business_day.before(first)
expected = Date.parse("April 12th, 2010")
assert_equal expected, after
end
it "move backward one week when adding -5 business days" do
first = Date.parse("April 16th, 2010")
before = -5.business_days.after(first)
expected = Date.parse("April 9th, 2010")
assert_equal expected, before
end
it "move forward one week when subtracting -5 business days" do
first = Date.parse("April 9th, 2010")
after = -5.business_days.before(first)
expected = Date.parse("April 16th, 2010")
assert_equal expected, after
end
it "take into account a holiday when adding a negative day" do
three_day_weekend = Date.parse("July 5th, 2010")
BusinessTime::Config.holidays << three_day_weekend
tuesday_afternoon = Date.parse("July 6th, 2010")
friday_afternoon = -1.business_day.after(tuesday_afternoon)
expected = Date.parse("July 2nd, 2010")
assert_equal expected, friday_afternoon
end
it "take into account a holiday on a weekend" do
july_4 = Date.parse("July 4th, 2010")
BusinessTime::Config.holidays << july_4
monday_afternoon = Date.parse("July 5nd, 2010")
friday_afternoon = -1.business_day.after(monday_afternoon)
expected = Date.parse("July 2nd, 2010")
assert_equal expected, friday_afternoon
end
it "move to thursday if we add one negative business day during a weekend" do
saturday = Date.parse("April 10th, 2010")
before = -1.business_days.after(saturday)
expected = Date.parse("April 8th, 2010")
assert_equal expected, before
end
it "move to Monday if we subtract one negative business day during a weekend" do
saturday = Date.parse("April 10th, 2010")
after = -1.business_days.before(saturday)
expected = Date.parse("April 12th, 2010")
assert_equal expected, after
end
it "take into account a holiday passed as an option when adding a negative day" do
three_day_weekend = Date.parse("July 5th, 2010")
tuesday_afternoon = Date.parse("July 6th, 2010")
friday_afternoon = -1.business_day.after(tuesday_afternoon, holidays: [three_day_weekend])
expected = Date.parse("July 2nd, 2010")
assert_equal expected, friday_afternoon
end
it "take into account a holiday on a weekend passed as an option" do
july_4 = Date.parse("July 4th, 2010")
monday_afternoon = Date.parse("July 5nd, 2010")
friday_afternoon = -1.business_day.after(monday_afternoon, holidays: [july_4])
expected = Date.parse("July 2nd, 2010")
assert_equal expected, friday_afternoon
end
it "take into account a holiday passed as an option when adding a day" do
three_day_weekend = Date.parse("July 5th, 2010")
friday_afternoon = Date.parse("July 2nd, 2010")
tuesday_afternoon = 1.business_day.after(friday_afternoon, holidays: [three_day_weekend])
expected = Date.parse("July 6th, 2010")
assert_equal expected, tuesday_afternoon
end
it "take into account a holiday on a weekend passed as an option" do
july_4 = Date.parse("July 4th, 2010")
friday_afternoon = Date.parse("July 2nd, 2010")
monday_afternoon = 1.business_day.after(friday_afternoon, holidays: [july_4])
expected = Date.parse("July 5th, 2010")
assert_equal expected, monday_afternoon
end
end
end
end