workpattern 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,206 +0,0 @@
1
- module Workpattern
2
-
3
- # Represents the 60 minutes of an hour using an <tt>Integer</tt>
4
- #
5
- # @since 0.2.0
6
- #
7
- module Hour
8
-
9
- # Returns the total working minutes in the hour
10
- #
11
- # @return [Integer] working minutes in the hour
12
- #
13
- def wp_total
14
- return wp_minutes(0,59)
15
- end
16
-
17
- # Sets the minutes to either working (type=1) or resting (type=0)
18
- #
19
- # @param [Integer] start minute at start of range
20
- # @param [Integer] finish minute at end of range
21
- # @param [Integer] type defines whether working (1) or resting (0)
22
- #
23
- def wp_workpattern(start,finish,type=1)
24
- return wp_working(start,finish) if type==1
25
- return wp_resting(start,finish) if type==0
26
- end
27
-
28
- # Returns the first working minute in the hour or 60 if there are no working minutes
29
- #
30
- # @return [Integer] first working minute or 60 if none found
31
- #
32
- def wp_first
33
- 0.upto(59) {|minute| return minute if self.wp_minutes(minute,minute)==1}
34
- return nil
35
- end
36
-
37
- # Returns the last working minute in the hour or nil if there are no working minutes
38
- #
39
- # @return [Integer] last working minute or nil if none found
40
- #
41
- def wp_last
42
- 59.downto(0) {|minute| return minute if self.wp_minutes(minute,minute)==1}
43
- return nil
44
- end
45
-
46
- # Returns true if the given minute is working and false if it isn't
47
- #
48
- # @param [Integer] start is the minute being tested
49
- # @return [Boolean] true if minute is working, otherwise false
50
- #
51
- def wp_working?(start)
52
- return true if wp_minutes(start,start)==1
53
- return false
54
- end
55
-
56
- # Returns the total number of minutes between and including two minutes
57
- #
58
- # @param [Integer] start first minute in range
59
- # @param [Integer] finish last minute in range
60
- # @return [Integer] number of minutes from <tt>start</tt> to <tt>finish</tt> inclusive
61
- #
62
- def wp_minutes(start,finish)
63
- return (self & wp_mask(start,finish)).to_s(2).count('1')
64
- end
65
-
66
- # Returns the DateTime and remainding minutes when adding a duration to a minute in the hour.
67
- # A negative duration will subtract the minutes.
68
- #
69
- # @param [DateTime] time is the full date but only the minute element is used
70
- # @param [Integer] duration is the number of minutes to add and can be negative (subtraction)
71
- # @param [Boolean] next_hour used in subtraction to specify the starting point as midnight (00:00 the next day)
72
- # @return [DateTime,Integer,Boolean] The <tt>DateTime</tt> calculated along with remaining minutes and a flag indicating if starting point is next hour
73
- #
74
- def wp_calc(time,duration,next_hour=false)
75
- return wp_subtract(time,duration, next_hour) if duration < 0
76
- return wp_add(time,duration) if duration > 0
77
- return time,duration
78
- end
79
-
80
- # Returns the number of minutes between two minutes
81
- # @param [Integer] start first minute in range
82
- # @param [Integer] finish last minute in range
83
- # @return [Integer] number of working minutes in the range
84
- #
85
- def wp_diff(start,finish)
86
- start,finish=finish,start if start > finish
87
- return 0 if start==finish
88
- return (self & wp_mask(start,finish-1)).to_s(2).count('1')
89
- end
90
-
91
- private
92
-
93
- # Sets a working pattern
94
- #
95
- # @param [Integer] start is first minute in the range
96
- # @param [Integer] finish is last minute in the range
97
- #
98
- def wp_working(start,finish)
99
- return self | wp_mask(start,finish)
100
- end
101
-
102
- # sets a resting pattern
103
- #
104
- # @param [Integer] start is first minute in the range
105
- # @param [Integer] finish is last minute in the range
106
- #
107
- def wp_resting(start,finish)
108
- return self & ((2**60-1)-wp_mask(start,finish))
109
- end
110
-
111
- # Creates a bit mask of 1's over the specified range
112
- #
113
- # @param [Integer] start is first minute in the range
114
- # @param [Integer] finish is the last minute in the range
115
- #
116
- def wp_mask(start,finish)
117
- return ((2**(finish+1)-1)-(2**start-1))
118
- end
119
-
120
- # Handles the addition of minutes to a time
121
- #
122
- # @param [DateTime] time is the full date but only the minute element is used
123
- # @param [Integer] duration is the number of minutes to add and can be negative (subtraction)
124
- # @return [DateTime, Integer] The resulting DateTime and any remaining minutes
125
- #
126
- def wp_add(time,duration)
127
- start = time.min
128
- available_minutes=wp_minutes(start,59)
129
-
130
- if not_enough_minutes duration, available_minutes
131
- result_date = time + HOUR - (MINUTE*start)
132
- result_remainder = duration-available_minutes
133
- elsif exact_amount_of_minutes(start,duration)
134
- result_date = time + (MINUTE*duration)
135
- result_remainder = 0
136
- else # more than enough minutes
137
- step = start + duration
138
- duration-=wp_minutes(start,step)
139
- until (duration==0)
140
- step+=1
141
- duration-=wp_minutes(step,step)
142
- end
143
- step+=1
144
- result_date = time - (MINUTE*time.min) + (MINUTE*step)
145
- result_remainder = 0
146
- end
147
- return result_date, result_remainder
148
- end
149
-
150
- # Handles the subtraction of minutes from a time.
151
- # @param [DateTime] time is the full date but only the minute element is used
152
- # @param [Integer] duration is the number of minutes to add and can be negative (subtraction)
153
- # @param [Boolean] next_hour indicates if the 59th second is the first one to be included
154
- # @return [DateTime, Integer] The resulting DateTime and any remaining minutes
155
- #
156
- def wp_subtract(time,duration,next_hour)
157
- if next_hour
158
- duration += 1 if wp_working?(59)
159
- time = time + (MINUTE * 59)
160
- return wp_calc(time,duration)
161
- else
162
- start=time.min
163
- start > 0 ? available_minutes = wp_minutes(0,start-1) : available_minutes=0
164
- end
165
-
166
- if not_enough_minutes duration, available_minutes
167
- result_date = time - (MINUTE * start)
168
- result_remainder = duration + available_minutes
169
- elsif duration.abs == available_minutes
170
- result_date = time - (MINUTE * (start - wp_first))
171
- result_remainder = 0
172
- else
173
- step = start + duration
174
- duration += wp_minutes(step, start - 1)
175
- until (duration == 0)
176
- step -= 1
177
- duration += wp_minutes(step,step)
178
- end
179
- result_date = time - (MINUTE * (start - step))
180
- result_remainder = 0
181
- end
182
- return result_date, result_remainder
183
-
184
- end
185
-
186
- private
187
-
188
-
189
- def not_enough_minutes(duration,available_minutes)
190
- return true if (duration.abs-available_minutes)>0
191
- return false
192
- end
193
-
194
- def exact_amount_of_minutes(start,duration)
195
- return true if wp_minutes(start,start+duration-1)==duration
196
- false
197
- end
198
- end
199
- end
200
-
201
- # Hours are represented by a bitwise <tt>Integer</tt> class so the code is mixed in to that class
202
- # @ since 0.3.0
203
- #
204
- class Integer
205
- include Workpattern::Hour
206
- end
@@ -1,558 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestDay < MiniTest::Unit::TestCase #:nodoc:
4
-
5
- def setup
6
- @working_day = Workpattern::Day.new(1)
7
- @resting_day = Workpattern::Day.new(0)
8
- @pattern_day = Workpattern::Day.new(1)
9
- @pattern_day.workpattern(clock(0,0),clock(8,33),0)
10
- @pattern_day.workpattern(clock(12,0),clock(12,21),0)
11
- @pattern_day.workpattern(clock(12,30),clock(12,59),0)
12
- @pattern_day.workpattern(clock(17,0),clock(22,59),0)
13
- end
14
-
15
- def test_must_create_a_working_day
16
- assert_equal 1440, @working_day.total,"24 hour working total minutes"
17
- end
18
-
19
- def test_must_ceate_a_resting_day
20
- assert_equal 0, @resting_day.total,"24 hour resting total minutes"
21
- end
22
-
23
- def test_must_set_patterns_correctly
24
- mins=[0,0,0,0,0,0,0,0,26,60,60,60,8,60,60,60,60,0,0,0,0,0,0,60]
25
- mins.each_index {|index|
26
- assert_equal mins[index],@pattern_day.values[index].wp_total,"#{index} hour should be #{mins[index]} minutes"
27
- }
28
- assert_equal 514, @pattern_day.total, "total working minutes"
29
- assert_equal 8, @pattern_day.first_hour, "first hour of the day"
30
- assert_equal 34, @pattern_day.first_min, "first minute of the day"
31
- assert_equal 23, @pattern_day.last_hour, "last hour of the day"
32
- assert_equal 59, @pattern_day.last_min, "last minute of the day"
33
- end
34
-
35
- def test_must_duplicate_a_working_day
36
- dup_day = @working_day.duplicate
37
- assert_equal 1440, dup_day.total
38
- assert_equal 0, dup_day.first_hour
39
- assert_equal 0, dup_day.first_min
40
- assert_equal 23, dup_day.last_hour
41
- assert_equal 59, dup_day.last_min
42
- hour=Workpattern::WORKING_HOUR
43
- dup_day.values.each {|item|
44
- assert_equal hour, item
45
- }
46
- end
47
-
48
- def test_must_duplicate_a_resting_day
49
- dup_day = @resting_day.duplicate
50
- assert_equal 0, dup_day.total
51
- assert_nil dup_day.first_hour
52
- assert_nil dup_day.first_min
53
- assert_nil dup_day.last_hour
54
- assert_nil dup_day.last_min
55
- hour=Workpattern::RESTING_HOUR
56
- dup_day.values.each {|item|
57
- assert_equal hour, item
58
- }
59
- end
60
-
61
- def test_must_duplicate_a_patterned_day
62
- dup_day = @pattern_day.duplicate
63
-
64
- mins=[0,0,0,0,0,0,0,0,26,60,60,60,8,60,60,60,60,0,0,0,0,0,0,60]
65
- mins.each_index {|index|
66
- assert_equal mins[index],dup_day.values[index].wp_total,"#{index} hour should be #{mins[index]} minutes"
67
- }
68
-
69
- assert_equal 514, dup_day.total, "total working minutes"
70
- assert_equal 8, dup_day.first_hour, "first hour of the day"
71
- assert_equal 34, dup_day.first_min, "first minute of the day"
72
- assert_equal 23, dup_day.last_hour, "last hour of the day"
73
- assert_equal 59, dup_day.last_min, "last minute of the day"
74
-
75
- end
76
-
77
- def test_must_add_more_than_available_minutes_to_a_working_day
78
- start_date=DateTime.new(2013,1,1,8,15)
79
- result, remainder=@working_day.calc(start_date,946)
80
- assert_equal DateTime.new(2013,1,2,0,0), result
81
- assert_equal 1,remainder
82
- end
83
-
84
- def test_must_add_less_than_available_minutes_to_a_working_day
85
- start_date=DateTime.new(2013,1,1,8,15)
86
- result, remainder=@working_day.calc(start_date,944)
87
- assert_equal DateTime.new(2013,1,1,23,59), result
88
- assert_equal 0,remainder
89
- end
90
-
91
- def test_must_add_exactly_the_available_minutes_to_a_working_day
92
- start_date=DateTime.new(2013,1,1,8,15)
93
- result, remainder=@working_day.calc(start_date,945)
94
- assert_equal DateTime.new(2013,1,2,0,0), result
95
- assert_equal 0,remainder
96
- end
97
-
98
- def test_must_add_zero_minutes_to_a_working_day
99
- start_date=DateTime.new(2013,1,1,8,15)
100
- result, remainder=@working_day.calc(start_date,0)
101
- assert_equal start_date, result
102
- assert_equal 0,remainder
103
- end
104
-
105
- def test_must_add_1_minute_to_0_in_working_day
106
- start_date=DateTime.new(2013,1,1,0,0)
107
- result, remainder=@working_day.calc(start_date,1)
108
- assert_equal DateTime.new(2013,1,1,0,1), result
109
- assert_equal 0,remainder
110
- end
111
-
112
- def test_must_add_1_hour_to_0_in_working_day
113
- start_date=DateTime.new(2013,1,1,0,0)
114
- result, remainder=@working_day.calc(start_date,60)
115
- assert_equal DateTime.new(2013,1,1,1,0), result
116
- assert_equal 0,remainder
117
- end
118
-
119
- def test_must_add_1_hour_1_minute_to_0_in_working_day
120
- start_date=DateTime.new(2013,1,1,0,0)
121
- result, remainder=@working_day.calc(start_date,61)
122
- assert_equal DateTime.new(2013,1,1,1,1), result
123
- assert_equal 0,remainder
124
- end
125
-
126
- def test_must_add_1_day_to_0_in_working_day
127
- start_date=DateTime.new(2013,1,1,0,0)
128
- result, remainder=@working_day.calc(start_date,1440)
129
- assert_equal DateTime.new(2013,1,2,0,0), result
130
- assert_equal 0,remainder
131
- end
132
-
133
- def test_must_add_1_day_1_minute_to_0_in_working_day
134
- start_date=DateTime.new(2013,1,1,0,0)
135
- result, remainder=@working_day.calc(start_date,1441)
136
- assert_equal DateTime.new(2013,1,2,0,0), result
137
- assert_equal 1,remainder
138
- end
139
-
140
- def test_must_add_more_than_available_minutes_to_a_resting_day
141
- start_date=DateTime.new(2013,1,1,8,15)
142
- result, remainder=@resting_day.calc(start_date,946)
143
- assert_equal DateTime.new(2013,1,2,0,0), result
144
- assert_equal 946,remainder
145
- end
146
-
147
- def test_must_add_less_than_available_minutes_to_a_resting_day
148
- start_date=DateTime.new(2013,1,1,8,15)
149
- result, remainder=@resting_day.calc(start_date,944)
150
- assert_equal DateTime.new(2013,1,2,0,0), result
151
- assert_equal 944,remainder
152
- end
153
-
154
- def test_must_add_exactly_the_available_minutes_to_a_resting_day
155
- start_date=DateTime.new(2013,1,1,8,15)
156
- result, remainder=@resting_day.calc(start_date,945)
157
- assert_equal DateTime.new(2013,1,2,0,0), result
158
- assert_equal 945,remainder
159
- end
160
-
161
- def test_must_add_zero_minutes_to_a_resting_day
162
- start_date=DateTime.new(2013,1,1,8,15)
163
- result, remainder=@resting_day.calc(start_date,0)
164
- assert_equal start_date, result
165
- assert_equal 0,remainder
166
- end
167
-
168
- def test_must_add_1_minute_to_0_in_resting_day
169
- start_date=DateTime.new(2013,1,1,0,0)
170
- result, remainder=@resting_day.calc(start_date,1)
171
- assert_equal DateTime.new(2013,1,2,0,0), result
172
- assert_equal 1,remainder
173
- end
174
-
175
- def test_must_add_1_hour_to_0_in_resting_day
176
- start_date=DateTime.new(2013,1,1,0,0)
177
- result, remainder=@resting_day.calc(start_date,60)
178
- assert_equal DateTime.new(2013,1,2,0,0), result
179
- assert_equal 60,remainder
180
- end
181
-
182
- def test_must_add_1_hour_1_minute_to_0_in_resting_day
183
- start_date=DateTime.new(2013,1,1,0,0)
184
- result, remainder=@resting_day.calc(start_date,61)
185
- assert_equal DateTime.new(2013,1,2,0,0), result
186
- assert_equal 61,remainder
187
- end
188
-
189
- def test_must_add_1_day_to_0_in_resting_day
190
- start_date=DateTime.new(2013,1,1,0,0)
191
- result, remainder=@resting_day.calc(start_date,1440)
192
- assert_equal DateTime.new(2013,1,2,0,0), result
193
- assert_equal 1440,remainder
194
- end
195
-
196
- def test_must_add_1_day_1_minute_to_0_in_resting_day
197
- start_date=DateTime.new(2013,1,1,0,0)
198
- result, remainder=@resting_day.calc(start_date,1441)
199
- assert_equal DateTime.new(2013,1,2,0,0), result
200
- assert_equal 1441,remainder
201
- end
202
-
203
- def test_must_add_more_than_available_minutes_to_a_pattern_day
204
- start_date=DateTime.new(2013,1,1,8,15)
205
- result, remainder=@pattern_day.calc(start_date,515)
206
- assert_equal DateTime.new(2013,1,2,0,0), result
207
- assert_equal 1,remainder
208
- end
209
-
210
- def test_must_add_less_than_available_minutes_to_a_pattern_day
211
- start_date=DateTime.new(2013,1,1,8,15)
212
- result, remainder=@pattern_day.calc(start_date,513)
213
- assert_equal DateTime.new(2013,1,1,23,59), result
214
- assert_equal 0,remainder
215
- end
216
-
217
- def test_must_add_exactly_the_available_minutes_to_a_pattern_day
218
- start_date=DateTime.new(2013,1,1,8,15)
219
- result, remainder=@pattern_day.calc(start_date,514)
220
- assert_equal DateTime.new(2013,1,2,0,0), result
221
- assert_equal 0,remainder
222
- end
223
-
224
- def test_must_add_zero_minutes_to_a_pattern_day
225
- start_date=DateTime.new(2013,1,1,8,15)
226
- result, remainder=@pattern_day.calc(start_date,0)
227
- assert_equal start_date, result
228
- assert_equal 0,remainder
229
- end
230
-
231
- def test_must_add_1_minute_to_0_in_pattern_day
232
- start_date=DateTime.new(2013,1,1,0,0)
233
- result, remainder=@pattern_day.calc(start_date,1)
234
- assert_equal DateTime.new(2013,1,1,8,35), result
235
- assert_equal 0,remainder
236
- end
237
-
238
- def test_must_add_1_hour_to_0_in_pattern_day
239
- start_date=DateTime.new(2013,1,1,0,0)
240
- result, remainder=@pattern_day.calc(start_date,60)
241
- assert_equal DateTime.new(2013,1,1,9,34), result
242
- assert_equal 0,remainder
243
- end
244
-
245
- def test_must_add_1_hour_1_minute_to_0_in_pattern_day
246
- start_date=DateTime.new(2013,1,1,0,0)
247
- result, remainder=@pattern_day.calc(start_date,61)
248
- assert_equal DateTime.new(2013,1,1,9,35), result
249
- assert_equal 0,remainder
250
- end
251
-
252
- def test_must_add_1_day_to_0_in_pattern_day
253
- start_date=DateTime.new(2013,1,1,0,0)
254
- result, remainder=@pattern_day.calc(start_date,1440)
255
- assert_equal DateTime.new(2013,1,2,0,0), result
256
- assert_equal 926,remainder
257
- end
258
-
259
- def test_must_add_1_day_1_minute_to_0_in_pattern_day
260
- start_date=DateTime.new(2013,1,1,0,0)
261
- result, remainder=@pattern_day.calc(start_date,1441)
262
- assert_equal DateTime.new(2013,1,2,0,0), result
263
- assert_equal 927,remainder
264
- end
265
-
266
- def test_must_subtract_more_than_available_minutes_in_working_day
267
- start_date=DateTime.new(2013,1,1,12,23)
268
- result, remainder, midnight=@working_day.calc(start_date,-744)
269
- assert_equal DateTime.new(2012,12,31,0,0), result
270
- assert_equal -1,remainder
271
- assert midnight
272
- end
273
-
274
- def test_must_subtract_less_than_available_minutes_in_working_day
275
- start_date=DateTime.new(2013,1,1,12,23)
276
- result, remainder, midnight=@working_day.calc(start_date,-742)
277
- assert_equal DateTime.new(2013,1,1,0,1), result
278
- assert_equal 0,remainder
279
- refute midnight
280
- end
281
-
282
- def test_must_subtract_available_minutes_in_working_day
283
- start_date=DateTime.new(2013,1,1,12,23)
284
- result, remainder, midnight=@working_day.calc(start_date,-743)
285
- assert_equal DateTime.new(2013,1,1,0,0), result
286
- assert_equal 0,remainder
287
- refute midnight
288
- end
289
-
290
- def test_must_subtract_1_minute_from_start_of_working_day
291
- start_date=DateTime.new(2013,1,1,0,0)
292
- result, remainder, midnight=@working_day.calc(start_date,-1)
293
- assert_equal DateTime.new(2012,12,31,0,0), result
294
- assert_equal -1,remainder
295
- assert midnight
296
- end
297
-
298
- def test_must_subtract_1_minute_from_start_of_next_working_day
299
- start_date=DateTime.new(2013,1,1,0,0)
300
- result, remainder, midnight=@working_day.calc(start_date,-1,true)
301
- assert_equal DateTime.new(2013,1,1,23,59), result
302
- assert_equal 0,remainder
303
- refute midnight
304
- end
305
-
306
- def test_must_subtract_1_day_from_start_of_next_working_day
307
- start_date=DateTime.new(2013,1,1,0,0)
308
- result, remainder, midnight=@working_day.calc(start_date,-1440,true)
309
- assert_equal DateTime.new(2013,1,1,0,0), result
310
- assert_equal 0,remainder
311
- refute midnight
312
- end
313
-
314
- def test_must_subtract_1_from_zero_minutes_from_resting_day
315
- start_date=DateTime.new(2013,1,1,0,0)
316
- result, remainder, midnight=@resting_day.calc(start_date,-1,true)
317
- assert_equal DateTime.new(2012,12,31,0,0), result
318
- assert_equal -1,remainder
319
- assert midnight
320
- end
321
-
322
- def test_must_subtract_1_from_resting_day
323
- start_date=DateTime.new(2013,1,1,4,13)
324
- result, remainder, midnight=@resting_day.calc(start_date,-1,true)
325
- assert_equal DateTime.new(2012,12,31,0,0), result
326
- assert_equal -1,remainder
327
- assert midnight
328
- end
329
-
330
- def test_must_subtract_1_from_zero_minutes_from_resting_day
331
- start_date=DateTime.new(2013,1,1,0,0)
332
- result, remainder, midnight=@resting_day.calc(start_date,-1,false)
333
- assert_equal DateTime.new(2012,12,31,0,0), result
334
- assert_equal -1,remainder
335
- assert midnight
336
- end
337
-
338
- def test_must_subtract_1_from_somewhere_in_resting_day
339
- start_date=DateTime.new(2013,1,1,4,13)
340
- result, remainder, midnight=@resting_day.calc(start_date,-1,false)
341
- assert_equal DateTime.new(2012,12,31,0,0), result
342
- assert_equal -1,remainder
343
- assert midnight
344
- end
345
-
346
- def test_must_subtract_more_than_available_minutes_in_patterned_day
347
- start_date=DateTime.new(2013,1,1,12,23)
348
- result, remainder, midnight=@pattern_day.calc(start_date,-208)
349
- assert_equal DateTime.new(2012,12,31,0,0), result
350
- assert_equal -1,remainder
351
- assert midnight
352
- end
353
-
354
- def test_must_subtract_less_than_available_minutes_in_patterned_day
355
- start_date=DateTime.new(2013,1,1,12,23)
356
- result, remainder, midnight=@pattern_day.calc(start_date,-206)
357
- assert_equal DateTime.new(2013,1,1,8,35), result
358
- assert_equal 0,remainder
359
- refute midnight
360
- end
361
-
362
- def test_must_subtract_available_minutes_in_patterned_day
363
- start_date=DateTime.new(2013,1,1,12,23)
364
- result, remainder, midnight=@pattern_day.calc(start_date,-207)
365
- assert_equal DateTime.new(2013,1,1,8,34), result
366
- assert_equal 0,remainder
367
- refute midnight
368
- end
369
-
370
- def test_must_subtract_1_minute_from_start_of_patterned_day
371
- start_date=DateTime.new(2013,1,1,0,0)
372
- result, remainder, midnight=@pattern_day.calc(start_date,-1)
373
- assert_equal DateTime.new(2012,12,31,0,0), result
374
- assert_equal -1,remainder
375
- assert midnight
376
- end
377
-
378
- def test_must_subtract_1_minute_from_start_of_next_patterned_day
379
- start_date=DateTime.new(2013,1,1,0,0)
380
- result, remainder, midnight=@pattern_day.calc(start_date,-1,true)
381
- assert_equal DateTime.new(2013,1,1,23,59), result
382
- assert_equal 0,remainder
383
- refute midnight
384
- end
385
-
386
- def test_must_subtract_1_day_from_start_of_next_patterned_day
387
- start_date=DateTime.new(2013,1,1,0,0)
388
- result, remainder, midnight=@pattern_day.calc(start_date,-514,true)
389
- assert_equal DateTime.new(2013,1,1,8,34), result
390
- assert_equal 0,remainder
391
- refute midnight
392
- end
393
-
394
- def test_must_return_0_difference_between_same_time_in_working_day
395
- start_date=DateTime.new(2013,1,1,8,32)
396
- difference,result_date=@working_day.diff(start_date,start_date)
397
- assert_equal 0, difference
398
- assert_equal start_date, result_date
399
- end
400
-
401
- def test_must_return_difference_to_end_of_day_using_different_days_in_working_day
402
- start_date=DateTime.new(2013,1,1,23,30)
403
- finish_date=DateTime.new(2013,1,2,8,1)
404
- difference,result_date=@working_day.diff(start_date,finish_date)
405
- assert_equal 30, difference
406
- assert_equal DateTime.new(2013,1,2,0,0), result_date
407
- end
408
-
409
- def test_must_return_difference_to_from_start_of_day_to_end_of_day_using_different_days_in_working_day
410
- start_date=DateTime.new(2013,1,1,0,0)
411
- finish_date=DateTime.new(2013,1,2,8,1)
412
- difference,result_date=@working_day.diff(start_date,finish_date)
413
- assert_equal 1440, difference
414
- assert_equal DateTime.new(2013,1,2,0,0), result_date
415
- end
416
-
417
- def test_must_return_difference_from_start_of_day_in_working_day
418
- start_date=DateTime.new(2013,1,1,0,0)
419
- finish_date=DateTime.new(2013,1,1,3,1)
420
- difference,result_date=@working_day.diff(start_date,finish_date)
421
- assert_equal 181, difference
422
- assert_equal finish_date, result_date
423
- end
424
-
425
- def test_must_return_difference_between_two_times_in_working_day
426
- start_date=DateTime.new(2013,1,1,2,11)
427
- finish_date=DateTime.new(2013,1,1,9,15)
428
- difference,result_date=@working_day.diff(start_date,finish_date)
429
- assert_equal 424, difference
430
- assert_equal finish_date, result_date
431
- end
432
-
433
- def test_must_return_0_difference_between_same_time_in_resting_day
434
- start_date=DateTime.new(2013,1,1,8,32)
435
- difference,result_date=@resting_day.diff(start_date,start_date)
436
- assert_equal 0, difference
437
- assert_equal start_date, result_date
438
- end
439
-
440
- def test_must_return_difference_to_end_of_day_using_different_days_in_resting_day
441
- start_date=DateTime.new(2013,1,1,23,30)
442
- finish_date=DateTime.new(2013,1,2,8,1)
443
- difference,result_date=@resting_day.diff(start_date,finish_date)
444
- assert_equal 0, difference
445
- assert_equal DateTime.new(2013,1,2,0,0), result_date
446
- end
447
-
448
- def test_must_return_difference_to_from_start_of_day_to_end_of_day_using_different_days_in_resting_day
449
- start_date=DateTime.new(2013,1,1,0,0)
450
- finish_date=DateTime.new(2013,1,2,8,1)
451
- difference,result_date=@resting_day.diff(start_date,finish_date)
452
- assert_equal 0, difference
453
- assert_equal DateTime.new(2013,1,2,0,0), result_date
454
- end
455
-
456
- def test_must_return_difference_from_start_of_day_in_resting_day
457
- start_date=DateTime.new(2013,1,1,0,0)
458
- finish_date=DateTime.new(2013,1,1,3,1)
459
- difference,result_date=@resting_day.diff(start_date,finish_date)
460
- assert_equal 0, difference
461
- assert_equal finish_date, result_date
462
- end
463
-
464
- def test_must_return_difference_between_two_times_in_resting_day
465
- start_date=DateTime.new(2013,1,1,2,11)
466
- finish_date=DateTime.new(2013,1,1,9,15)
467
- difference,result_date=@resting_day.diff(start_date,finish_date)
468
- assert_equal 0, difference
469
- assert_equal finish_date, result_date
470
- end
471
-
472
- ####
473
-
474
- def test_must_return_0_difference_between_same_working_time_in_patterned_day
475
- start_date=DateTime.new(2013,1,1,8,34)
476
- difference,result_date=@pattern_day.diff(start_date,start_date)
477
- assert_equal 0, difference
478
- assert_equal start_date, result_date
479
- end
480
-
481
- def test_must_return_0_difference_between_same_resting_time_in_patterned_day
482
- start_date=DateTime.new(2013,1,1,8,32)
483
- difference,result_date=@pattern_day.diff(start_date,start_date)
484
- assert_equal 0, difference
485
- assert_equal start_date, result_date
486
- end
487
-
488
- def test_must_return_difference_to_end_of_day_from_working_time_using_different_days_in_patterned_day
489
- start_date=DateTime.new(2013,1,1,12,23)
490
- finish_date=DateTime.new(2013,1,2,8,1)
491
- difference,result_date=@pattern_day.diff(start_date,finish_date)
492
- assert_equal 307, difference
493
- assert_equal DateTime.new(2013,1,2,0,0), result_date
494
- end
495
-
496
- def test_must_return_difference_to_end_of_day_from_resting_time_using_different_days_in_patterned_day
497
- start_date=DateTime.new(2013,1,1,12,10)
498
- finish_date=DateTime.new(2013,1,2,8,1)
499
- difference,result_date=@pattern_day.diff(start_date,finish_date)
500
- assert_equal 308, difference
501
- assert_equal DateTime.new(2013,1,2,0,0), result_date
502
- end
503
-
504
- def test_must_return_difference_to_from_start_of_day_to_end_of_day_using_different_days_in_pattern_day
505
- start_date=DateTime.new(2013,1,1,0,0)
506
- finish_date=DateTime.new(2013,1,2,8,1)
507
- difference,result_date=@pattern_day.diff(start_date,finish_date)
508
- assert_equal 514, difference
509
- assert_equal DateTime.new(2013,1,2,0,0), result_date
510
- end
511
-
512
- def test_must_return_difference_from_start_of_day_in_pattern_day
513
- start_date=DateTime.new(2013,1,1,0,0)
514
- finish_date=DateTime.new(2013,1,1,11,1)
515
- difference,result_date=@pattern_day.diff(start_date,finish_date)
516
- assert_equal 147, difference
517
- assert_equal finish_date, result_date
518
- end
519
-
520
- def test_must_return_difference_between_two_working_times_in_pattern_day
521
- start_date=DateTime.new(2013,1,1,8,45)
522
- finish_date=DateTime.new(2013,1,1,12,26)
523
- difference,result_date=@pattern_day.diff(start_date,finish_date)
524
- assert_equal 199, difference
525
- assert_equal finish_date, result_date
526
- end
527
-
528
- def test_must_return_difference_between_two_resting_times_in_pattern_day
529
- start_date=DateTime.new(2013,1,1,8,20)
530
- finish_date=DateTime.new(2013,1,1,12,40)
531
- difference,result_date=@pattern_day.diff(start_date,finish_date)
532
- assert_equal 214, difference
533
- assert_equal finish_date, result_date
534
- end
535
-
536
- def test_must_return_difference_between_working_and_resting_times_in_pattern_day
537
- start_date=DateTime.new(2013,1,1,8,45)
538
- finish_date=DateTime.new(2013,1,1,12,40)
539
- difference,result_date=@pattern_day.diff(start_date,finish_date)
540
- assert_equal 203, difference
541
- assert_equal finish_date, result_date
542
- end
543
-
544
- def test_must_return_difference_between_resting_and_working_times_in_pattern_day
545
- start_date=DateTime.new(2013,1,1,12,15)
546
- finish_date=DateTime.new(2013,1,1,23,30)
547
- difference,result_date=@pattern_day.diff(start_date,finish_date)
548
- assert_equal 278, difference
549
- assert_equal finish_date, result_date
550
- end
551
-
552
- private
553
-
554
- def clock(hour,min)
555
- return Workpattern.clock(hour,min)
556
- end
557
- end
558
-