workpattern 0.3.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +8 -4
- data/.travis.yml +18 -3
- data/CHANGELOG.md +88 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -4
- data/LICENSE.txt +21 -0
- data/README.md +56 -80
- data/Rakefile +9 -0
- data/lib/workpattern.rb +31 -91
- data/lib/workpattern/clock.rb +21 -20
- data/lib/workpattern/constants.rb +72 -0
- data/lib/workpattern/day.rb +211 -290
- data/lib/workpattern/version.rb +2 -4
- data/lib/workpattern/week.rb +239 -321
- data/lib/workpattern/week_pattern.rb +144 -0
- data/lib/workpattern/workpattern.rb +156 -187
- data/workpattern.gemspec +32 -18
- metadata +40 -28
- data/CHANGELOG +0 -35
- data/config/website.yml +0 -2
- data/lib/workpattern/hour.rb +0 -209
- data/lib/workpattern/utility/base.rb +0 -32
- data/test/test_clock.rb +0 -31
- data/test/test_day.rb +0 -522
- data/test/test_helper.rb +0 -3
- data/test/test_hour.rb +0 -389
- data/test/test_week.rb +0 -362
- data/test/test_workpattern.rb +0 -276
- data/test/test_workpattern_module.rb +0 -93
data/test/test_helper.rb
DELETED
data/test/test_hour.rb
DELETED
@@ -1,389 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestHour < MiniTest::Unit::TestCase #:nodoc:
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@working_hour = Workpattern::WORKING_HOUR
|
7
|
-
@resting_hour = Workpattern::RESTING_HOUR
|
8
|
-
@pattern_hour = @working_hour
|
9
|
-
@pattern_hour = @pattern_hour.wp_workpattern(0,0,0)
|
10
|
-
@pattern_hour = @pattern_hour.wp_workpattern(59,59,0)
|
11
|
-
@pattern_hour = @pattern_hour.wp_workpattern(11,30,0)
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_for_default_working_hour_of_60_minutes
|
16
|
-
assert_equal 60, @working_hour.wp_total,"working total minutes"
|
17
|
-
assert_equal 0, @working_hour.wp_first,"first minute of the working hour"
|
18
|
-
assert_equal 59, @working_hour.wp_last, "last minute of the working hour"
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_for_default_resting_hour_of_0_minutes
|
22
|
-
assert_equal 0, @resting_hour.wp_total,"resting total minutes"
|
23
|
-
assert_equal nil, @resting_hour.wp_first,"first minute of the resting hour"
|
24
|
-
assert_equal nil, @resting_hour.wp_last, "last minute of the resting hour"
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_for_creating_a_workpattern_in_an_hour
|
28
|
-
assert_equal 38,@pattern_hour.wp_total, "total working minutes in pattern"
|
29
|
-
assert_equal 1, @pattern_hour.wp_first, "first minute of the pattern hour"
|
30
|
-
assert_equal 58, @pattern_hour.wp_last, "last minute of the pattern hour"
|
31
|
-
refute @pattern_hour.wp_working?(0)
|
32
|
-
assert @pattern_hour.wp_working?(1)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_for_creating_8_33_that_failed_in_test_day
|
36
|
-
test_hour=@working_hour.wp_workpattern(0,33,0)
|
37
|
-
assert_equal 26, test_hour.wp_total
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_can_add_more_than_the_available_minutes_in_a_working_hour
|
41
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
42
|
-
result, remainder=@working_hour.wp_calc(start_date,53)
|
43
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
44
|
-
assert_equal 1,remainder
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_can_add_exact_amount_of_available_minutes_in_working_hour
|
48
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
49
|
-
result, remainder=@working_hour.wp_calc(start_date,52)
|
50
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
51
|
-
assert_equal 0,remainder
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_can_add_when_more_available_minutes_in_working_hour
|
55
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
56
|
-
result, remainder=@working_hour.wp_calc(start_date,51)
|
57
|
-
assert_equal DateTime.new(2013,1,1,1,59), result
|
58
|
-
assert_equal 0,remainder
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_can_add_1_minute_to_59_seconds_in_working_hour
|
62
|
-
start_date=DateTime.new(2013,1,1,1,59)
|
63
|
-
result, remainder=@working_hour.wp_calc(start_date,1)
|
64
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
65
|
-
assert_equal 0,remainder
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_can_add_2_minute_to_59_seconds_in_working_hour
|
69
|
-
start_date=DateTime.new(2013,1,1,1,59)
|
70
|
-
result, remainder=@working_hour.wp_calc(start_date,2)
|
71
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
72
|
-
assert_equal 1,remainder
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_can_subtract_more_than_the_available_minutes_in_a_working_hour
|
76
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
77
|
-
result, remainder=@working_hour.wp_calc(start_date,-32)
|
78
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
79
|
-
assert_equal -1,remainder
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_can_subtract_exact_amount_of_available_minutes_in_working_hour
|
83
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
84
|
-
result, remainder=@working_hour.wp_calc(start_date,-31)
|
85
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
86
|
-
assert_equal 0,remainder
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_can_subtract_1_second_less_than_available_minutes_in_working_hour
|
90
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
91
|
-
result, remainder=@working_hour.wp_calc(start_date,-30)
|
92
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
93
|
-
assert_equal 0,remainder
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_can_subtract_when_more_available_minutes_in_working_hour
|
97
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
98
|
-
result, remainder=@working_hour.wp_calc(start_date,-30)
|
99
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
100
|
-
assert_equal 0,remainder
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_can_subtract_1_minute_from_0_seconds_in_working_hour
|
104
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
105
|
-
result, remainder=@working_hour.wp_calc(start_date,-1)
|
106
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
107
|
-
assert_equal -1,remainder
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_can_subtract_2_minute_to_0_seconds_in_working_hour
|
111
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
112
|
-
result, remainder=@working_hour.wp_calc(start_date,-2)
|
113
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
114
|
-
assert_equal -2,remainder
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_can_subtract_exact_minutes_from_start_of_a_working_hour
|
118
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
119
|
-
result, remainder=@working_hour.wp_calc(start_date,-60,true)
|
120
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
121
|
-
assert_equal 0,remainder
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_can_subtract_less_than_available_minutes_from_start_of_a_working_hour
|
125
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
126
|
-
result, remainder=@working_hour.wp_calc(start_date,-59,true)
|
127
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
128
|
-
assert_equal 0,remainder
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_can_subtract_more_than_available_minutes_from_start_of_a_working_hour
|
132
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
133
|
-
result, remainder=@working_hour.wp_calc(start_date,-61,true)
|
134
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
135
|
-
assert_equal -1,remainder
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_can_subtract_1_minute_from_end_of_a_working_hour
|
139
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
140
|
-
result, remainder=@working_hour.wp_calc(start_date,-1,true)
|
141
|
-
assert_equal DateTime.new(2013,1,1,1,59), result
|
142
|
-
assert_equal 0,remainder
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_can_zero_minutes_in_a_working_hour
|
146
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
147
|
-
result, remainder=@working_hour.wp_calc(start_date,0)
|
148
|
-
assert_equal DateTime.new(2013,1,1,1,8), result
|
149
|
-
assert_equal 0,remainder
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_can_add_1_minute_to_a_resting_hour
|
153
|
-
start_date=DateTime.new(2013,1,1,1,30)
|
154
|
-
result, remainder=@resting_hour.wp_calc(start_date,1)
|
155
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
156
|
-
assert_equal 1,remainder
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_can_add_1_minute_to_59_seconds_of_resting_hour
|
160
|
-
start_date=DateTime.new(2013,1,1,1,59)
|
161
|
-
result, remainder=@resting_hour.wp_calc(start_date,1)
|
162
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
163
|
-
assert_equal 1,remainder
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_can_add_1_minute_to_0_seconds_of_resting_hour
|
167
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
168
|
-
result, remainder=@resting_hour.wp_calc(start_date,1)
|
169
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
170
|
-
assert_equal 1,remainder
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_can_subtract_0_minutes_from_start_of_a_resting_hour
|
174
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
175
|
-
result, remainder=@resting_hour.wp_calc(start_date,0,true)
|
176
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
177
|
-
assert_equal 0,remainder
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_can_subtract_1_minute_from_end_of_a_resting_hour
|
181
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
182
|
-
result, remainder=@resting_hour.wp_calc(start_date,-1,true)
|
183
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
184
|
-
assert_equal -1,remainder
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_can_zero_minutes_in_a_resting_hour
|
188
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
189
|
-
result, remainder=@resting_hour.wp_calc(start_date,0)
|
190
|
-
assert_equal DateTime.new(2013,1,1,1,8), result
|
191
|
-
assert_equal 0,remainder
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_can_add_more_than_the_available_minutes_in_a_patterned_hour
|
195
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
196
|
-
result, remainder=@pattern_hour.wp_calc(start_date,32)
|
197
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
198
|
-
assert_equal 1,remainder
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_can_add_exact_amount_of_available_minutes_in_patterned_hour
|
202
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
203
|
-
result, remainder=@pattern_hour.wp_calc(start_date,31)
|
204
|
-
assert_equal DateTime.new(2013,1,1,1,59), result
|
205
|
-
assert_equal 0,remainder
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_can_add_when_more_available_minutes_in_patterned_hour
|
209
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
210
|
-
result, remainder=@pattern_hour.wp_calc(start_date,30)
|
211
|
-
assert_equal DateTime.new(2013,1,1,1,58), result
|
212
|
-
assert_equal 0,remainder
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_can_add_from_resting_period_in_patterned_hour
|
216
|
-
start_date=DateTime.new(2013,1,1,1,15)
|
217
|
-
result, remainder=@pattern_hour.wp_calc(start_date,1)
|
218
|
-
assert_equal DateTime.new(2013,1,1,1,32), result
|
219
|
-
assert_equal 0,remainder
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_can_add_1_subtract_1_to_find_next_working_period_in_patterned_hour
|
223
|
-
start_date=DateTime.new(2013,1,1,1,15)
|
224
|
-
start_date, remainder=@pattern_hour.wp_calc(start_date,1)
|
225
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-1)
|
226
|
-
assert_equal DateTime.new(2013,1,1,1,31), result
|
227
|
-
assert_equal 0,remainder
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_can_add_zero_minutes_in_a_working_period_patterned_hour
|
231
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
232
|
-
result, remainder=@pattern_hour.wp_calc(start_date,0)
|
233
|
-
assert_equal DateTime.new(2013,1,1,1,8), result
|
234
|
-
assert_equal 0,remainder
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_can_zero_minutes_in_a_resting_period_patterned_hour
|
238
|
-
start_date=DateTime.new(2013,1,1,1,15)
|
239
|
-
result, remainder=@pattern_hour.wp_calc(start_date,0)
|
240
|
-
assert_equal DateTime.new(2013,1,1,1,15), result
|
241
|
-
assert_equal 0,remainder
|
242
|
-
end
|
243
|
-
|
244
|
-
def test_minutes_in_slice_of_working_hour
|
245
|
-
assert_equal 8,@working_hour.wp_minutes(8,15)
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_minutes_in_slice_of_resting_hour
|
249
|
-
assert_equal 0,@resting_hour.wp_minutes(8,15)
|
250
|
-
end
|
251
|
-
|
252
|
-
def test_minutes_in_slice_of_working_hour
|
253
|
-
assert_equal 3,@pattern_hour.wp_minutes(8,15)
|
254
|
-
assert_equal 4,@pattern_hour.wp_minutes(8,31)
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_can_subtract_more_than_the_available_minutes_in_a_pattern_hour
|
258
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
259
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-11)
|
260
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
261
|
-
assert_equal -1,remainder
|
262
|
-
end
|
263
|
-
|
264
|
-
def test_can_subtract_exact_amount_of_available_minutes_in_pattern_hour
|
265
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
266
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-10)
|
267
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
268
|
-
assert_equal 0,remainder
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_can_subtract_1_second_less_than_available_minutes_in_pattern_hour
|
272
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
273
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-9)
|
274
|
-
assert_equal DateTime.new(2013,1,1,1,2), result
|
275
|
-
assert_equal 0,remainder
|
276
|
-
end
|
277
|
-
|
278
|
-
def test_can_change_working_to_resting
|
279
|
-
new_hour=@working_hour.wp_workpattern(0,59,0)
|
280
|
-
assert_equal 0,new_hour.wp_total
|
281
|
-
assert_nil new_hour.wp_first
|
282
|
-
assert_nil new_hour.wp_last
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_must_create_complex_patterns
|
286
|
-
new_hour=@working_hour.wp_workpattern(0,0,0)
|
287
|
-
new_hour=new_hour.wp_workpattern(8,23,0)
|
288
|
-
new_hour=new_hour.wp_workpattern(12,12,1)
|
289
|
-
new_hour=new_hour.wp_workpattern(58,58,0)
|
290
|
-
new_hour=new_hour.wp_workpattern(6,8,1)
|
291
|
-
assert_equal 44, new_hour.wp_total
|
292
|
-
assert_equal 1, new_hour.wp_first
|
293
|
-
assert_equal 59, new_hour.wp_last
|
294
|
-
end
|
295
|
-
|
296
|
-
def test_difference_between_first_and_last_minute_in_working_hour
|
297
|
-
assert_equal 59, @working_hour.wp_diff(0,59)
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_difference_between_first_and_first_minute_in_working_hour
|
301
|
-
assert_equal 0, @working_hour.wp_diff(0,0)
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_difference_between_last_and_last_minute_in_working_hour
|
305
|
-
assert_equal 0, @working_hour.wp_diff(59,59)
|
306
|
-
end
|
307
|
-
|
308
|
-
def test_difference_between_two_minutes_in_working_hour
|
309
|
-
assert_equal 13, @working_hour.wp_diff(3,16)
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_difference_between_first_minute_and_first_minute_in_next_hour_in_working_hour
|
313
|
-
assert_equal 60, @working_hour.wp_diff(0,60)
|
314
|
-
end
|
315
|
-
|
316
|
-
def test_difference_between_a_minute_and_last_minute_in_working_hour
|
317
|
-
assert_equal 43, @working_hour.wp_diff(16,59)
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_differences_work_in_reverse_for_working_hour
|
321
|
-
assert_equal 59, @working_hour.wp_diff(59,0)
|
322
|
-
assert_equal 13, @working_hour.wp_diff(16,3)
|
323
|
-
assert_equal 60, @working_hour.wp_diff(60,0)
|
324
|
-
assert_equal 43, @working_hour.wp_diff(59,16)
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_difference_between_first_and_last_minute_in_resting_hour
|
328
|
-
assert_equal 0, @resting_hour.wp_diff(0,59)
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_difference_between_first_and_first_minute_in_resting_hour
|
332
|
-
assert_equal 0, @resting_hour.wp_diff(0,0)
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_difference_between_last_and_last_minute_in_resting_hour
|
336
|
-
assert_equal 0, @resting_hour.wp_diff(59,59)
|
337
|
-
end
|
338
|
-
|
339
|
-
def test_difference_between_two_minutes_in_resting_hour
|
340
|
-
assert_equal 0, @resting_hour.wp_diff(3,16)
|
341
|
-
end
|
342
|
-
|
343
|
-
def test_difference_between_first_minute_and_first_minute_in_next_hour_in_resting_hour
|
344
|
-
assert_equal 0, @resting_hour.wp_diff(0,60)
|
345
|
-
end
|
346
|
-
|
347
|
-
def test_difference_between_a_minute_and_last_minute_in_resting_hour
|
348
|
-
assert_equal 0, @resting_hour.wp_diff(16,59)
|
349
|
-
end
|
350
|
-
|
351
|
-
def test_differences_work_in_reverse_for_resting_hour
|
352
|
-
assert_equal 0, @resting_hour.wp_diff(59,0)
|
353
|
-
assert_equal 0, @resting_hour.wp_diff(16,3)
|
354
|
-
assert_equal 0, @resting_hour.wp_diff(60,0)
|
355
|
-
assert_equal 0, @resting_hour.wp_diff(59,16)
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_difference_between_first_and_last_minute_in_pattern_hour
|
359
|
-
assert_equal 38, @pattern_hour.wp_diff(0,59)
|
360
|
-
end
|
361
|
-
|
362
|
-
def test_difference_between_first_and_first_minute_in_pattern_hour
|
363
|
-
assert_equal 0, @pattern_hour.wp_diff(0,0)
|
364
|
-
end
|
365
|
-
|
366
|
-
def test_difference_between_last_and_last_minute_in_pattern_hour
|
367
|
-
assert_equal 0, @pattern_hour.wp_diff(59,59)
|
368
|
-
end
|
369
|
-
|
370
|
-
def test_difference_between_two_minutes_in_pattern_hour
|
371
|
-
assert_equal 8, @pattern_hour.wp_diff(3,16)
|
372
|
-
end
|
373
|
-
|
374
|
-
def test_difference_between_first_minute_and_first_minute_in_next_hour_in_pattern_hour
|
375
|
-
assert_equal 38, @pattern_hour.wp_diff(0,60)
|
376
|
-
end
|
377
|
-
|
378
|
-
def test_difference_between_a_minute_and_last_minute_in_pattern_hour
|
379
|
-
assert_equal 28, @pattern_hour.wp_diff(16,59)
|
380
|
-
end
|
381
|
-
|
382
|
-
def test_differences_work_in_reverse_for_pattern_hour
|
383
|
-
assert_equal 38, @pattern_hour.wp_diff(59,0)
|
384
|
-
assert_equal 8, @pattern_hour.wp_diff(16,3)
|
385
|
-
assert_equal 38, @pattern_hour.wp_diff(60,0)
|
386
|
-
assert_equal 28, @pattern_hour.wp_diff(59,16)
|
387
|
-
end
|
388
|
-
|
389
|
-
end
|
data/test/test_week.rb
DELETED
@@ -1,362 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestWeek < MiniTest::Unit::TestCase #:nodoc:
|
4
|
-
|
5
|
-
def setup
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_must_diff_from_last_day_of_patterned_week
|
10
|
-
#issue 15
|
11
|
-
start=DateTime.new(2013,9,23,0,0)
|
12
|
-
finish=DateTime.new(2013,9,26,23,59)
|
13
|
-
working_week=week(start,finish,1)
|
14
|
-
working_week.workpattern :all, Workpattern.clock(0,0),Workpattern.clock(8,59),0
|
15
|
-
working_week.workpattern :all, Workpattern.clock(12,0),Workpattern.clock(12,59),0
|
16
|
-
working_week.workpattern :all, Workpattern.clock(18,0),Workpattern.clock(23,59),0
|
17
|
-
|
18
|
-
duration, start =working_week.diff(DateTime.civil(2013,9,26,17,0),DateTime.civil(2013,9,27,10,0))
|
19
|
-
|
20
|
-
assert_equal 60, duration
|
21
|
-
assert_equal DateTime.civil(2013,9,27,0,0), start
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
######################################################
|
26
|
-
######################################################
|
27
|
-
######################################################
|
28
|
-
|
29
|
-
def test_must_create_a_working_week
|
30
|
-
start=DateTime.new(2000,1,1,11,3)
|
31
|
-
finish=DateTime.new(2005,12,31,16,41)
|
32
|
-
working_week=week(start,finish,1)
|
33
|
-
assert_equal DateTime.new(start.year,start.month,start.day), working_week.start
|
34
|
-
assert_equal DateTime.new(finish.year,finish.month,finish.day), working_week.finish
|
35
|
-
assert_equal 3156480, working_week.total#2192
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_must_create_a_resting_week
|
39
|
-
start=DateTime.new(2000,1,1,11,3)
|
40
|
-
finish=DateTime.new(2005,12,31,16,41)
|
41
|
-
resting_week=week(start,finish,0)
|
42
|
-
assert_equal DateTime.new(start.year,start.month,start.day), resting_week.start
|
43
|
-
assert_equal DateTime.new(finish.year,finish.month,finish.day), resting_week.finish
|
44
|
-
assert_equal 0, resting_week.total#2192
|
45
|
-
assert_equal 0,resting_week.week_total
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_must_duplicate_all_of_a_week
|
49
|
-
start=DateTime.new(2000,1,1,11,3)
|
50
|
-
finish=DateTime.new(2005,12,31,16,41)
|
51
|
-
week=week(start,finish,1)
|
52
|
-
new_week=week.duplicate
|
53
|
-
assert_equal DateTime.new(start.year,start.month,start.day), new_week.start
|
54
|
-
assert_equal DateTime.new(finish.year,finish.month,finish.day), new_week.finish
|
55
|
-
assert_equal 3156480, new_week.total#2192
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_must_set_patterns_correctly
|
60
|
-
start=DateTime.new(2000,1,1,0,0)
|
61
|
-
finish=DateTime.new(2005,12,31,8,59)
|
62
|
-
working_week=week(start,finish,1)
|
63
|
-
assert_equal 10080, working_week.week_total
|
64
|
-
working_week.workpattern(:all,start,finish,0)
|
65
|
-
assert_equal 6300, working_week.week_total
|
66
|
-
working_week.workpattern(:sun,start,finish,1)
|
67
|
-
assert_equal 6840, working_week.week_total
|
68
|
-
working_week.workpattern(:mon,start,finish,1)
|
69
|
-
assert_equal 7380, working_week.week_total
|
70
|
-
working_week.workpattern(:all,clock(18,0),clock(18,19),0)
|
71
|
-
assert_equal 7240, working_week.week_total
|
72
|
-
working_week.workpattern(:all,clock(0,0),clock(23,59),0)
|
73
|
-
assert_equal 0, working_week.week_total
|
74
|
-
working_week.workpattern(:all,clock(0,0),clock(0,0),1)
|
75
|
-
assert_equal 7, working_week.week_total
|
76
|
-
working_week.workpattern(:all,clock(23,59),clock(23,59),1)
|
77
|
-
assert_equal 14, working_week.week_total
|
78
|
-
working_week.workpattern(:all,clock(0,0),clock(23,59),1)
|
79
|
-
assert_equal 10080, working_week.week_total
|
80
|
-
working_week.workpattern(:weekend,clock(0,0),clock(23,59),0)
|
81
|
-
assert_equal 7200, working_week.week_total
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_must_add_minutes_in_a_working_week
|
86
|
-
start=DateTime.new(2000,1,1,0,0)
|
87
|
-
finish=DateTime.new(2005,12,31,8,59)
|
88
|
-
working_week=week(start,finish,1)
|
89
|
-
|
90
|
-
[# yyyy,mm,dd,hh,mn,durtn,ryyyy,rmm,rdd,rhh,rmn,rdurtn
|
91
|
-
[ 2000, 1, 1, 0, 0, 0, 2000, 1, 1, 0, 0, 0],
|
92
|
-
[ 2005,12,31, 8,59, 10, 2005, 12, 31, 9, 9, 0],
|
93
|
-
[ 2005,12,31,23,59, 1, 2006, 1, 1, 0, 0, 0],
|
94
|
-
[ 2005,12,31,23,59, 2, 2006, 1, 1, 0, 0, 1],
|
95
|
-
[ 2005,11,30,23,59, 2, 2005, 12, 1, 0, 1, 0]
|
96
|
-
].each {|yyyy,mm,dd,hh,mn,durtn,ryyyy,rmm,rdd,rhh,rmn,rdurtn|
|
97
|
-
start=DateTime.new(yyyy,mm,dd,hh,mn)
|
98
|
-
result_date, result_duration= working_week.calc(start,durtn)
|
99
|
-
assert_equal DateTime.new(ryyyy,rmm,rdd,rhh,rmn), result_date, "result_date for working_week.calc(#{start},#{durtn})"
|
100
|
-
assert_equal rdurtn, result_duration,"result_duration for working_week.calc(#{start},#{durtn})"
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_must_add_minutes_in_a_resting_week
|
105
|
-
start=DateTime.new(2000,1,1,0,0)
|
106
|
-
finish=DateTime.new(2005,12,31,8,59)
|
107
|
-
resting_week=week(start,finish,0)
|
108
|
-
|
109
|
-
[# yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight
|
110
|
-
[ 2000, 1, 1, 0, 0, 0, false, 2000, 1, 1, 0, 0, 0, false],
|
111
|
-
[ 2005,12,31, 8,59, 10, false, 2006, 1, 1, 0, 0, 10, false],
|
112
|
-
[ 2005,12,31,23,59, 1, false, 2006, 1, 1, 0, 0, 1, false],
|
113
|
-
[ 2005,12,31,23,59, 2, false, 2006, 1, 1, 0, 0, 2, false],
|
114
|
-
[ 2005,11,30,23,59, 2, false, 2006, 1, 1, 0, 0, 2, false],
|
115
|
-
[ 2000, 1, 1, 0, 0, 0, true, 2000, 1, 1, 0, 0, 0, false],
|
116
|
-
[ 2005,12,31, 8,59, 10, true, 2006, 1, 1, 0, 0, 10, false],
|
117
|
-
[ 2005,12,31,23,59, 1, true, 2006, 1, 1, 0, 0, 1, false],
|
118
|
-
[ 2005,12,31,23,59, 2, true, 2006, 1, 1, 0, 0, 2, false],
|
119
|
-
[ 2005,11,30,23,59, 2, true, 2006, 1, 1, 0, 0, 2, false]
|
120
|
-
].each {|yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight|
|
121
|
-
start=DateTime.new(yyyy,mm,dd,hh,mn)
|
122
|
-
result_date, result_duration,result_midnight= resting_week.calc(start,durtn,midnight)
|
123
|
-
assert_equal DateTime.new(ryyyy,rmm,rdd,rhh,rmn), result_date, "result_date for resting_week.calc(#{start},#{durtn},#{midnight})"
|
124
|
-
assert_equal rdurtn, result_duration,"result_duration for resting_week.calc(#{start},#{durtn},#{midnight})"
|
125
|
-
assert_equal rmidnight, result_midnight,"result_midnight for resting_week.calc(#{start},#{durtn},#{midnight})"
|
126
|
-
}
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_must_add_minutes_in_a_patterned_week
|
130
|
-
start=DateTime.new(2000,1,1,0,0) #saturday
|
131
|
-
finish=DateTime.new(2005,12,31,8,59) #saturday
|
132
|
-
working_week=week(start,finish,0)
|
133
|
-
working_week.workpattern(:sun,clock(9,0),clock(9,13),1)
|
134
|
-
|
135
|
-
working_week.workpattern(:weekday,clock(9,0),clock(11,59),1)
|
136
|
-
working_week.workpattern(:weekday,clock(13,0),clock(17,59),1)
|
137
|
-
|
138
|
-
working_week.workpattern(:mon,clock(0,0),clock(23,59),0)
|
139
|
-
working_week.workpattern(:mon,clock(9,0),clock(9,13),1)
|
140
|
-
working_week.workpattern(:mon,clock(10,1),clock(10,1),1)
|
141
|
-
|
142
|
-
|
143
|
-
[# yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight
|
144
|
-
[ 2000, 1, 1, 0, 0, 0, false, 2000, 1, 1, 0, 0, 0, false],
|
145
|
-
[ 2000, 1, 1, 0, 0, 1, false, 2000, 1, 2, 9, 1, 0, false],
|
146
|
-
[ 2000, 1, 2, 9, 0, 14, false, 2000, 1, 2, 9, 14, 0, false], #Issue #9 - getting wrong time when hour had exactly the right number of minutes
|
147
|
-
[ 2000, 1, 2, 9, 0, 15, false, 2000, 1, 3, 9, 1, 0, false],
|
148
|
-
[ 2000, 1, 2, 9, 0, 29, false, 2000, 1, 3, 10, 2, 0, false],
|
149
|
-
[ 2000, 1, 2, 9, 0, 1950, false, 2000, 1, 9, 9, 1, 0, false],
|
150
|
-
[ 2005,12,25, 9, 0, 1950, false, 2006, 1, 1, 0, 0, 1, false],
|
151
|
-
[ 2005,12,25, 9, 0, 1949, false, 2005, 12, 30, 18, 0, 0, false]#,
|
152
|
-
].each {|yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight|
|
153
|
-
start=DateTime.new(yyyy,mm,dd,hh,mn)
|
154
|
-
result_date, result_duration,result_midnight= working_week.calc(start,durtn,midnight)
|
155
|
-
assert_equal DateTime.new(ryyyy,rmm,rdd,rhh,rmn), result_date, "result_date for working_week.calc(#{start},#{durtn},#{midnight})"
|
156
|
-
assert_equal rdurtn, result_duration,"result_duration for working_week.calc(#{start},#{durtn},#{midnight})"
|
157
|
-
assert_equal rmidnight, result_midnight,"result_midnight for working_week.calc(#{start},#{durtn},#{midnight})"
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_must_subtract_minutes_in_a_working_week
|
162
|
-
start=DateTime.new(2000,1,1,0,0)
|
163
|
-
finish=DateTime.new(2005,12,31,8,59)
|
164
|
-
working_week=week(start,finish,1)
|
165
|
-
[# yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight
|
166
|
-
[ 2000, 1, 1, 0, 0, 0, false, 2000, 1, 1, 0, 0, 0, false],
|
167
|
-
[ 2005,12,31, 0, 0, -10, false, 2005, 12, 30, 23, 50, 0, false],
|
168
|
-
[ 2005,12,31, 0, 0, -1, false, 2005, 12, 30, 23, 59, 0, false],
|
169
|
-
[ 2005,12,31, 0, 1, -2, false, 2005, 12, 30, 23, 59, 0, false], #Issue 6 - available minutes not calculating correctly for a time of 00:01
|
170
|
-
[ 2000, 1, 1, 0, 1, -2, false, 1999, 12, 31, 0, 0, -1, true], #Issue 6 - available minutes not calculating correctly for a time of 00:01
|
171
|
-
[ 2000, 1, 1, 0, 0, 0, true, 2000, 1, 1, 0, 0, 0, false],
|
172
|
-
[ 2005,12,31, 0, 0, -10, true, 2005, 12, 31, 23, 50, 0, false],
|
173
|
-
[ 2005,12,31, 0, 0, -1, true, 2005, 12, 31, 23, 59, 0, false],
|
174
|
-
[ 2005,12,31, 0, 1, -2, true, 2005, 12, 31, 23, 58, 0, false],#Issue 7 - midnight flag should override hour and minutes
|
175
|
-
[ 2000, 1, 1, 0, 1, -2, true, 2000, 1, 1, 23, 58, 0, false] #Issue 7 - midnight flag should override hour and minutes
|
176
|
-
].each {|yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight|
|
177
|
-
start=DateTime.new(yyyy,mm,dd,hh,mn)
|
178
|
-
result_date, result_duration,result_midnight= working_week.calc(start,durtn,midnight)
|
179
|
-
assert_equal DateTime.new(ryyyy,rmm,rdd,rhh,rmn), result_date, "result_date for working_week.calc(#{start},#{durtn},#{midnight})"
|
180
|
-
assert_equal rdurtn, result_duration,"result_duration for working_week.calc(#{start},#{durtn},#{midnight})"
|
181
|
-
assert_equal rmidnight, result_midnight,"result_midnight for working_week.calc(#{start},#{durtn},#{midnight})"
|
182
|
-
}
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_must_subtract_minutes_in_a_resting_week
|
186
|
-
start=DateTime.new(2000,1,1,0,0)
|
187
|
-
finish=DateTime.new(2005,12,31,8,59)
|
188
|
-
resting_week=week(start,finish,0)
|
189
|
-
[# yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight
|
190
|
-
[ 2000, 1, 1, 0, 0, 0, false, 2000, 1, 1, 0, 0, 0, false],
|
191
|
-
[ 2005,12,31, 0, 0, -10, false, 1999, 12, 31, 0, 0, -10, true],
|
192
|
-
[ 2005,12,31, 0, 0, -1, false, 1999, 12, 31, 0, 0, -1, true],
|
193
|
-
[ 2005,12,31, 0, 1, -2, false, 1999, 12, 31, 0, 0, -2, true],
|
194
|
-
[ 2000, 1, 1, 0, 1, -2, false, 1999, 12, 31, 0, 0, -2, true]
|
195
|
-
].each {|yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight|
|
196
|
-
start=DateTime.new(yyyy,mm,dd,hh,mn)
|
197
|
-
result_date, result_duration, result_midnight= resting_week.calc(start,durtn,midnight)
|
198
|
-
assert_equal DateTime.new(ryyyy,rmm,rdd,rhh,rmn), result_date, "result_date for resting_week.calc(#{start},#{durtn},#{midnight})"
|
199
|
-
assert_equal rdurtn, result_duration,"result_duration for resting_week.calc(#{start},#{durtn},#{midnight})"
|
200
|
-
assert_equal rmidnight, result_midnight,"result_midnight for resting_week.calc(#{start},#{durtn},#{midnight})"
|
201
|
-
}
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_must_subtract_minutes_in_a_patterned_week
|
205
|
-
start=DateTime.new(2000,1,1,0,0) #saturday
|
206
|
-
finish=DateTime.new(2005,12,31,8,59) #saturday
|
207
|
-
working_week=week(start,finish,0)
|
208
|
-
working_week.workpattern(:sun,clock(9,0),clock(9,13),1)
|
209
|
-
|
210
|
-
working_week.workpattern(:weekday,clock(9,0),clock(11,59),1)
|
211
|
-
working_week.workpattern(:weekday,clock(13,0),clock(17,59),1)
|
212
|
-
|
213
|
-
working_week.workpattern(:mon,clock(0,0),clock(23,59),0)
|
214
|
-
working_week.workpattern(:mon,clock(9,0),clock(9,13),1)
|
215
|
-
working_week.workpattern(:mon,clock(10,1),clock(10,1),1)
|
216
|
-
|
217
|
-
|
218
|
-
[# yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight
|
219
|
-
[ 2000, 1, 1, 0, 0, 0, false, 2000, 1, 1, 0, 0, 0, false],
|
220
|
-
[ 2000, 1, 1, 0, 0, -1, false, 1999, 12, 31, 0, 0, -1, true],
|
221
|
-
[ 2000, 1, 2, 9, 0, 14, false, 2000, 1, 2, 9, 14, 0, false],
|
222
|
-
[ 2000, 1, 2, 9, 0, 15, false, 2000, 1, 3, 9, 1, 0, false],
|
223
|
-
[ 2000, 1, 2, 9, 0, 29, false, 2000, 1, 3, 10, 2, 0, false],
|
224
|
-
[ 2000, 1, 2, 9, 0, 1950, false, 2000, 1, 9, 9, 1, 0, false],
|
225
|
-
[ 2005,12,25, 9, 0, 1950, false, 2006, 1, 1, 0, 0, 1, false],
|
226
|
-
[ 2005,12,25, 9, 0, 1949, false, 2005, 12, 30, 18, 0, 0, false]#,
|
227
|
-
].each {|yyyy,mm,dd,hh,mn,durtn,midnight,ryyyy,rmm,rdd,rhh,rmn,rdurtn,rmidnight|
|
228
|
-
start=DateTime.new(yyyy,mm,dd,hh,mn)
|
229
|
-
result_date, result_duration,result_midnight= working_week.calc(start,durtn,midnight)
|
230
|
-
assert_equal DateTime.new(ryyyy,rmm,rdd,rhh,rmn), result_date, "result_date for working_week.calc(#{start},#{durtn},#{midnight})"
|
231
|
-
assert_equal rdurtn, result_duration,"result_duration for working_week.calc(#{start},#{durtn},#{midnight})"
|
232
|
-
assert_equal rmidnight, result_midnight,"result_midnight for working_week.calc(#{start},#{durtn},#{midnight})"
|
233
|
-
}
|
234
|
-
end
|
235
|
-
|
236
|
-
def test_must_calculate_difference_between_dates_in_working_week
|
237
|
-
start=DateTime.new(2012,10,1)
|
238
|
-
finish=DateTime.new(2012,10,7)
|
239
|
-
week=week(start,finish,1)
|
240
|
-
|
241
|
-
[
|
242
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 0, 0,2012,10, 1, 0, 0],
|
243
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 1, 1,2012,10, 1, 0, 1],
|
244
|
-
[ 2012,10, 1, 0,50, 2012,10, 1, 0,59, 9,2012,10, 1, 0,59],
|
245
|
-
[ 2012,10, 1, 8,50, 2012,10, 1, 9, 0, 10,2012,10, 1, 9, 0],
|
246
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1,23,59, 1439,2012,10, 1,23,59],
|
247
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 0, 1440,2012,10, 2, 0, 0],
|
248
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 1, 1441,2012,10, 2, 0, 1],
|
249
|
-
[ 2012,10, 1, 0, 0, 2013, 3,22, 6,11,10080,2012,10, 8, 0, 0],
|
250
|
-
[ 2012,10, 1, 0, 1, 2012,10, 1, 0, 0, 1,2012,10, 1, 0, 1],
|
251
|
-
[ 2012,10, 1, 0,59, 2012,10, 1, 0,50, 9,2012,10, 1, 0,59],
|
252
|
-
[ 2012,10, 1, 9, 0, 2012,10, 1, 8,50, 10,2012,10, 1, 9, 0],
|
253
|
-
[ 2012,10, 1,23,59, 2012,10, 1, 0, 0, 1439,2012,10, 1,23,59],
|
254
|
-
[ 2012,10, 2, 0, 0, 2012,10, 1, 0, 0, 1440,2012,10, 2, 0, 0],
|
255
|
-
[ 2012,10, 2, 0, 1, 2012,10, 1, 0, 0, 1441,2012,10, 2, 0, 1],
|
256
|
-
[ 2013, 3,22, 6,11, 2012,10, 1, 0, 0,10080,2012,10, 8, 0, 0],
|
257
|
-
[ 2012,10, 2, 6,11, 2012,10, 4, 8, 9, 2998,2012,10, 4, 8, 9]
|
258
|
-
].each {|start_year, start_month, start_day, start_hour,start_min,
|
259
|
-
finish_year, finish_month, finish_day, finish_hour,finish_min,result,
|
260
|
-
y,m,d,h,n|
|
261
|
-
start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
|
262
|
-
finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
|
263
|
-
expected_date=DateTime.new(y,m,d,h,n)
|
264
|
-
duration, result_date=week.diff(start,finish)
|
265
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
266
|
-
assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
|
267
|
-
}
|
268
|
-
end
|
269
|
-
|
270
|
-
def test_must_calculate_difference_between_dates_in_resting_week
|
271
|
-
|
272
|
-
start=DateTime.new(2012,10,1)
|
273
|
-
finish=DateTime.new(2012,10,7)
|
274
|
-
week=week(start,finish,0)
|
275
|
-
|
276
|
-
[
|
277
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 0, 0,2012,10, 1, 0, 0],
|
278
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 1, 0,2012,10, 1, 0, 1],
|
279
|
-
[ 2012,10, 1, 0,50, 2012,10, 1, 0,59, 0,2012,10, 1, 0,59],
|
280
|
-
[ 2012,10, 1, 8,50, 2012,10, 1, 9, 0, 0,2012,10, 1, 9, 0],
|
281
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1,23,59, 0,2012,10, 1,23,59],
|
282
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 0, 0,2012,10, 2, 0, 0],
|
283
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 1, 0,2012,10, 2, 0, 1],
|
284
|
-
[ 2012,10, 1, 0, 0, 2013, 3,22, 6,11, 0,2012,10, 8, 0, 0],
|
285
|
-
[ 2012,10, 1, 0, 1, 2012,10, 1, 0, 0, 0,2012,10, 1, 0, 1],
|
286
|
-
[ 2012,10, 1, 0,59, 2012,10, 1, 0,50, 0,2012,10, 1, 0,59],
|
287
|
-
[ 2012,10, 1, 9, 0, 2012,10, 1, 8,50, 0,2012,10, 1, 9, 0],
|
288
|
-
[ 2012,10, 1,23,59, 2012,10, 1, 0, 0, 0,2012,10, 1,23,59],
|
289
|
-
[ 2012,10, 2, 0, 0, 2012,10, 1, 0, 0, 0,2012,10, 2, 0, 0],
|
290
|
-
[ 2012,10, 2, 0, 1, 2012,10, 1, 0, 0, 0,2012,10, 2, 0, 1],
|
291
|
-
[ 2013, 3,22, 6,11, 2012,10, 1, 0, 0, 0,2012,10, 8, 0, 0]
|
292
|
-
].each {|start_year, start_month, start_day, start_hour,start_min,
|
293
|
-
finish_year, finish_month, finish_day, finish_hour,finish_min,result,
|
294
|
-
y,m,d,h,n|
|
295
|
-
start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
|
296
|
-
finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
|
297
|
-
expected_date=DateTime.new(y,m,d,h,n)
|
298
|
-
duration, result_date=week.diff(start,finish)
|
299
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
300
|
-
assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
|
301
|
-
}
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_must_calculate_difference_between_dates_in_pattern_week
|
305
|
-
start=DateTime.new(2000,1,1)
|
306
|
-
finish=DateTime.new(2012,12,31)
|
307
|
-
week=week(start,finish,1)
|
308
|
-
return
|
309
|
-
[[0,0,8,59],
|
310
|
-
[12,0,12,59],
|
311
|
-
[17,0,22,59]
|
312
|
-
].each {|start_hour,start_min,finish_hour,finish_min|
|
313
|
-
week.workpattern(clock(start_hour, start_min),
|
314
|
-
clock(finish_hour, finish_min),
|
315
|
-
0)
|
316
|
-
}
|
317
|
-
assert_equal 480, day.total, "minutes in patterned day should be 480"
|
318
|
-
assert_equal 1, day.minutes(16,59,16,59),"16:59 should be 1"
|
319
|
-
assert_equal 0, day.minutes(17,0,17,0),"17:00 should be 0"
|
320
|
-
assert_equal 0, day.minutes(22,59,22,59),"22:59 should be 0"
|
321
|
-
assert_equal 1, day.minutes(23,0,23,0),"23:00 should be 1"
|
322
|
-
|
323
|
-
[
|
324
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 0, 0,2012,10, 1, 0, 0],
|
325
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 1, 0,2012,10, 1, 0, 1],
|
326
|
-
[ 2012,10, 1, 0,50, 2012,10, 1, 9,59, 59,2012,10, 1, 9,59],
|
327
|
-
[ 2012,10, 1, 8,50, 2012,10, 1, 9,10, 10,2012,10, 1, 9,10],
|
328
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1,23,59, 479,2012,10, 1,23,59],
|
329
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 0, 480,2012,10, 2, 0, 0],
|
330
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 1, 480,2012,10, 2, 0, 0],
|
331
|
-
[ 2012,10, 1, 0, 0, 2013, 3,22, 6,11, 480,2012,10, 2, 0, 0],
|
332
|
-
[ 2012,10, 1, 0, 1, 2012,10, 1, 0, 0, 0,2012,10, 1, 0, 1],
|
333
|
-
[ 2012,10, 1, 9,59, 2012,10, 1, 0,50, 59,2012,10, 1, 9,59],
|
334
|
-
[ 2012,10, 1, 9, 0, 2012,10, 1, 8,50, 0,2012,10, 1, 9, 0],
|
335
|
-
[ 2012,10, 1,23,59, 2012,10, 1, 0, 0, 479,2012,10, 1,23,59],
|
336
|
-
[ 2012,10, 2, 0, 0, 2012,10, 1, 0, 0, 480,2012,10, 2, 0, 0],
|
337
|
-
[ 2012,10, 2, 0, 1, 2012,10, 1, 0, 0, 480,2012,10, 2, 0, 0],
|
338
|
-
[ 2013, 3,22, 6,11, 2012,10, 1, 0, 0, 480,2012,10, 2, 0, 0]
|
339
|
-
].each {|start_year, start_month, start_day, start_hour,start_min,
|
340
|
-
finish_year, finish_month, finish_day, finish_hour,finish_min,result,
|
341
|
-
y,m,d,h,n|
|
342
|
-
start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
|
343
|
-
finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
|
344
|
-
expected_date=DateTime.new(y,m,d,h,n)
|
345
|
-
duration, result_date=day.diff(start,finish)
|
346
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
347
|
-
assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
|
348
|
-
}
|
349
|
-
|
350
|
-
end
|
351
|
-
|
352
|
-
private
|
353
|
-
|
354
|
-
def week(start,finish,type)
|
355
|
-
return Workpattern::Week.new(start,finish,type)
|
356
|
-
end
|
357
|
-
|
358
|
-
def clock(hour,min)
|
359
|
-
return Workpattern.clock(hour,min)
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|