workpattern 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/Rakefile +9 -0
- data/lib/workpattern.rb +1 -1
- data/lib/workpattern/clock.rb +10 -6
- data/lib/workpattern/day.rb +70 -51
- data/lib/workpattern/hour.rb +16 -19
- data/lib/workpattern/version.rb +1 -1
- data/lib/workpattern/week.rb +122 -100
- data/lib/workpattern/workpattern.rb +29 -41
- data/test/test_clock.rb +1 -0
- data/test/test_day.rb +200 -164
- data/test/test_helper.rb +0 -1
- data/test/test_hour.rb +7 -0
- data/test/test_week.rb +330 -257
- data/test/test_workpattern_module.rb +2 -13
- metadata +3 -3
@@ -50,21 +50,16 @@ module Workpattern
|
|
50
50
|
|
51
51
|
raise(NameError, "Workpattern '#{name}' already exists and can't be created again") if @@workpatterns.key?(name)
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
else
|
56
|
-
offset = 0
|
57
|
-
end
|
58
|
-
|
53
|
+
span < 0 ? offset = span.abs - 1 : offset = 0
|
54
|
+
|
59
55
|
@name = name
|
60
56
|
@base = base
|
61
57
|
@span = span
|
62
58
|
@from = DateTime.new(base.abs - offset)
|
63
|
-
@to = DateTime.new(
|
59
|
+
@to = DateTime.new(from.year + span.abs - 1,12,31,23,59)
|
64
60
|
@weeks = SortedSet.new
|
65
|
-
@weeks << Week.new(
|
66
|
-
|
67
|
-
|
61
|
+
@weeks << Week.new(from,to,1)
|
62
|
+
|
68
63
|
@@workpatterns[name]=self
|
69
64
|
end
|
70
65
|
|
@@ -95,11 +90,7 @@ module Workpattern
|
|
95
90
|
# @return [Boolean] true if the named <tt>Workpattern</tt> existed or false if it doesn't
|
96
91
|
#
|
97
92
|
def self.delete(name)
|
98
|
-
|
99
|
-
return false
|
100
|
-
else
|
101
|
-
return true
|
102
|
-
end
|
93
|
+
@@workpatterns.delete(name).nil? ? false : true
|
103
94
|
end
|
104
95
|
|
105
96
|
# Applys a working or resting pattern to the <tt>Workpattern</tt> object.
|
@@ -124,45 +115,43 @@ module Workpattern
|
|
124
115
|
#
|
125
116
|
def workpattern(opts={})
|
126
117
|
|
127
|
-
args={:start =>
|
118
|
+
args={:start => from, :finish => to, :days => :all,
|
128
119
|
:from_time => FIRST_TIME_IN_DAY, :to_time => LAST_TIME_IN_DAY,
|
129
120
|
:work_type => WORK}
|
130
121
|
|
131
122
|
args.merge! opts
|
132
123
|
|
133
|
-
@@persistence.store( name:
|
124
|
+
@@persistence.store( name: name, workpattern: args) if self.class.persistence?
|
134
125
|
|
135
126
|
args[:start] = dmy_date(args[:start])
|
136
127
|
args[:finish] = dmy_date(args[:finish])
|
137
|
-
from_time = hhmn_date(args[:from_time])
|
138
|
-
to_time = hhmn_date(args[:to_time])
|
139
|
-
|
128
|
+
args[:from_time] = hhmn_date(args[:from_time])
|
129
|
+
args[:to_time] = hhmn_date(args[:to_time])
|
130
|
+
|
140
131
|
upd_start=args[:start]
|
141
132
|
upd_finish=args[:finish]
|
142
133
|
while (upd_start <= upd_finish)
|
143
134
|
|
144
135
|
current_wp=find_weekpattern(upd_start)
|
136
|
+
|
145
137
|
if (current_wp.start == upd_start)
|
146
138
|
if (current_wp.finish > upd_finish)
|
147
139
|
clone_wp=clone_and_adjust_current_wp(current_wp, upd_finish+1,current_wp.finish,upd_start,upd_finish)
|
148
|
-
clone_wp
|
149
|
-
@weeks<< clone_wp
|
140
|
+
set_workpattern_and_store(clone_wp,args)
|
150
141
|
upd_start=upd_finish+1
|
151
142
|
else # (current_wp.finish == upd_finish)
|
152
|
-
current_wp.workpattern(args[:days],from_time,to_time,args[:work_type])
|
143
|
+
current_wp.workpattern(args[:days],args[:from_time],args[:to_time],args[:work_type])
|
153
144
|
upd_start=current_wp.finish + 1
|
154
145
|
end
|
155
146
|
else
|
156
147
|
clone_wp=clone_and_adjust_current_wp(current_wp, current_wp.start,upd_start-1,upd_start)
|
157
148
|
if (clone_wp.finish <= upd_finish)
|
158
|
-
clone_wp
|
159
|
-
@weeks<< clone_wp
|
149
|
+
set_workpattern_and_store(clone_wp,args)
|
160
150
|
upd_start=clone_wp.finish+1
|
161
151
|
else
|
162
152
|
after_wp=clone_and_adjust_current_wp(clone_wp, upd_start,upd_finish,upd_finish+1)
|
163
|
-
|
164
|
-
clone_wp
|
165
|
-
@weeks<< clone_wp
|
153
|
+
weeks<< after_wp
|
154
|
+
set_workpattern_and_store(clone_wp,args)
|
166
155
|
upd_start=clone_wp.finish+1
|
167
156
|
end
|
168
157
|
end
|
@@ -253,15 +242,15 @@ module Workpattern
|
|
253
242
|
def find_weekpattern(date)
|
254
243
|
# find the pattern that fits the date
|
255
244
|
#
|
256
|
-
if date
|
257
|
-
result = Week.new(DateTime.jd(0)
|
258
|
-
elsif date
|
259
|
-
result = Week.new(
|
245
|
+
if date<from
|
246
|
+
result = Week.new(DateTime.jd(0),from-MINUTE,1)
|
247
|
+
elsif date>to
|
248
|
+
result = Week.new(to+MINUTE,DateTime.new(9999),1)
|
260
249
|
else
|
261
250
|
|
262
251
|
date = DateTime.new(date.year,date.month,date.day)
|
263
252
|
|
264
|
-
result
|
253
|
+
result=weeks.find {|week| week.start <= date and week.finish >= date}
|
265
254
|
end
|
266
255
|
return result
|
267
256
|
end
|
@@ -283,21 +272,20 @@ module Workpattern
|
|
283
272
|
def hhmn_date(date)
|
284
273
|
return Clock.new(date.hour,date.min)
|
285
274
|
end
|
286
|
-
|
287
|
-
private
|
288
|
-
|
275
|
+
|
289
276
|
# Handles cloning of Week Pattern including date adjustments
|
290
277
|
#
|
291
278
|
def clone_and_adjust_current_wp(current_wp, current_start,current_finish,clone_start,clone_finish=nil)
|
292
279
|
clone_wp=current_wp.duplicate
|
293
280
|
current_wp.adjust(current_start,current_finish)
|
294
|
-
|
295
|
-
clone_wp.adjust(clone_start,clone_wp.finish)
|
296
|
-
else
|
297
|
-
clone_wp.adjust(clone_start,clone_finish)
|
298
|
-
end
|
281
|
+
clone_finish.nil? ? clone_wp.adjust(clone_start,clone_wp.finish) : clone_wp.adjust(clone_start,clone_finish)
|
299
282
|
return clone_wp
|
300
283
|
end
|
284
|
+
|
285
|
+
def set_workpattern_and_store(new_wp, args)
|
286
|
+
new_wp.workpattern(args[:days],args[:from_time],args[:to_time],args[:work_type])
|
287
|
+
weeks<< new_wp
|
288
|
+
end
|
301
289
|
end
|
302
290
|
end
|
303
291
|
|
data/test/test_clock.rb
CHANGED
@@ -25,6 +25,7 @@ class TestClock < MiniTest::Unit::TestCase #:nodoc:
|
|
25
25
|
assert_equal 20, clock.min, "minute is 20"
|
26
26
|
time = clock.time
|
27
27
|
assert time.kind_of?(DateTime), "must return a DateTime object"
|
28
|
+
assert_equal DateTime.new(1963,6,10,4,20), time
|
28
29
|
assert_equal 4, time.hour, "hour in the day must be 4"
|
29
30
|
assert_equal 20, time.min, "minute in the day must be 20"
|
30
31
|
end
|
data/test/test_day.rb
CHANGED
@@ -310,7 +310,7 @@ class TestDay < MiniTest::Unit::TestCase #:nodoc:
|
|
310
310
|
assert_equal 0,remainder
|
311
311
|
refute midnight
|
312
312
|
end
|
313
|
-
|
313
|
+
|
314
314
|
def test_must_subtract_1_from_zero_minutes_from_resting_day
|
315
315
|
start_date=DateTime.new(2013,1,1,0,0)
|
316
316
|
result, remainder, midnight=@resting_day.calc(start_date,-1,true)
|
@@ -343,177 +343,213 @@ class TestDay < MiniTest::Unit::TestCase #:nodoc:
|
|
343
343
|
assert midnight
|
344
344
|
end
|
345
345
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
assert_equal
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
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
|
393
399
|
end
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 1, 1,2000, 1, 1, 0, 1],
|
402
|
-
[ 2000, 1, 1, 0,50, 2000, 1, 1, 0,59, 9,2000, 1, 1, 0,59],
|
403
|
-
[ 2000, 1, 1, 8,50, 2000, 1, 1, 9, 0, 10,2000, 1, 1, 9, 0],
|
404
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 1,23,59,1439,2000, 1, 1,23,59],
|
405
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 0,1440,2000, 1, 2, 0, 0],
|
406
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 1,1440,2000, 1, 2, 0, 0],
|
407
|
-
[ 2000, 1, 1, 0, 0, 2010, 3,22, 6,11,1440,2000, 1, 2, 0, 0],
|
408
|
-
[ 2000, 1, 1, 0, 1, 2000, 1, 1, 0, 0, 1,2000, 1, 1, 0, 1],
|
409
|
-
[ 2000, 1, 1, 0,59, 2000, 1, 1, 0,50, 9,2000, 1, 1, 0,59],
|
410
|
-
[ 2000, 1, 1, 9, 0, 2000, 1, 1, 8,50, 10,2000, 1, 1, 9, 0],
|
411
|
-
[ 2000, 1, 1,23,59, 2000, 1, 1, 0, 0,1439,2000, 1, 1,23,59],
|
412
|
-
[ 2000, 1, 2, 0, 0, 2000, 1, 1, 0, 0,1440,2000, 1, 2, 0, 0],
|
413
|
-
[ 2000, 1, 2, 0, 1, 2000, 1, 1, 0, 0,1440,2000, 1, 2, 0, 0],
|
414
|
-
[ 2010, 3,22, 6,11, 2000, 1, 1, 0, 0,1440,2000, 1, 2, 0, 0]
|
415
|
-
].each {|start_year, start_month, start_day, start_hour,start_min,
|
416
|
-
finish_year, finish_month, finish_day, finish_hour,finish_min,result,
|
417
|
-
y,m,d,h,n|
|
418
|
-
start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
|
419
|
-
finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
|
420
|
-
expected_date=DateTime.new(y,m,d,h,n)
|
421
|
-
duration, result_date=day.diff(start,finish)
|
422
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
423
|
-
assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
|
424
|
-
}
|
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
|
425
407
|
end
|
426
408
|
|
427
|
-
def
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
[ 2000, 1, 1, 8,50, 2000, 1, 1, 9, 0, 0,2000, 1, 1, 9, 0],
|
435
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 1,23,59, 0,2000, 1, 1,23,59],
|
436
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 0, 0,2000, 1, 2, 0, 0],
|
437
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 1, 0,2000, 1, 2, 0, 0],
|
438
|
-
[ 2000, 1, 1, 0, 0, 2010, 3,22, 6,11, 0,2000, 1, 2, 0, 0],
|
439
|
-
[ 2000, 1, 1, 0, 1, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 1],
|
440
|
-
[ 2000, 1, 1, 0,59, 2000, 1, 1, 0,50, 0,2000, 1, 1, 0,59],
|
441
|
-
[ 2000, 1, 1, 9, 0, 2000, 1, 1, 8,50, 0,2000, 1, 1, 9, 0],
|
442
|
-
[ 2000, 1, 1,23,59, 2000, 1, 1, 0, 0, 0,2000, 1, 1,23,59],
|
443
|
-
[ 2000, 1, 2, 0, 0, 2000, 1, 1, 0, 0, 0,2000, 1, 2, 0, 0],
|
444
|
-
[ 2000, 1, 2, 0, 1, 2000, 1, 1, 0, 0, 0,2000, 1, 2, 0, 0],
|
445
|
-
[ 2010, 3,22, 6,11, 2000, 1, 1, 0, 0, 0,2000, 1, 2, 0, 0]
|
446
|
-
].each {|start_year, start_month, start_day, start_hour,start_min,
|
447
|
-
finish_year, finish_month, finish_day, finish_hour,finish_min,result,
|
448
|
-
y,m,d,h,n|
|
449
|
-
start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
|
450
|
-
finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
|
451
|
-
expected_date=DateTime.new(y,m,d,h,n)
|
452
|
-
duration, result_date=day.diff(start,finish)
|
453
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
454
|
-
assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
|
455
|
-
}
|
456
|
-
end
|
457
|
-
|
458
|
-
def test_must_calculate_difference_between_times_in_pattern_day
|
459
|
-
|
460
|
-
day = Workpattern::Day.new(1)
|
461
|
-
[[0,0,8,59],
|
462
|
-
[12,0,12,59],
|
463
|
-
[17,0,22,59]
|
464
|
-
].each {|start_hour,start_min,finish_hour,finish_min|
|
465
|
-
day.workpattern(clock(start_hour, start_min),
|
466
|
-
clock(finish_hour, finish_min),
|
467
|
-
0)
|
468
|
-
}
|
469
|
-
assert_equal 480, day.total, "minutes in patterned day should be 480"
|
470
|
-
assert_equal 1, day.minutes(16,59,16,59),"16:59 should be 1"
|
471
|
-
assert_equal 0, day.minutes(17,0,17,0),"17:00 should be 0"
|
472
|
-
assert_equal 0, day.minutes(22,59,22,59),"22:59 should be 0"
|
473
|
-
assert_equal 1, day.minutes(23,0,23,0),"23:00 should be 1"
|
474
|
-
|
475
|
-
[
|
476
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 0],
|
477
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 1, 0,2000, 1, 1, 0, 1],
|
478
|
-
[ 2000, 1, 1, 0,50, 2000, 1, 1, 9,59, 59,2000, 1, 1, 9,59],
|
479
|
-
[ 2000, 1, 1, 8,50, 2000, 1, 1, 9,10, 10,2000, 1, 1, 9,10],
|
480
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 1,23,59, 479,2000, 1, 1,23,59],
|
481
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 0, 480,2000, 1, 2, 0, 0],
|
482
|
-
[ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 1, 480,2000, 1, 2, 0, 0],
|
483
|
-
[ 2000, 1, 1, 0, 0, 2010, 3,22, 6,11, 480,2000, 1, 2, 0, 0],
|
484
|
-
[ 2000, 1, 1, 0, 1, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 1],
|
485
|
-
[ 2000, 1, 1, 9,59, 2000, 1, 1, 0,50, 59,2000, 1, 1, 9,59],
|
486
|
-
[ 2000, 1, 1, 9, 0, 2000, 1, 1, 8,50, 0,2000, 1, 1, 9, 0],
|
487
|
-
[ 2000, 1, 1,23,59, 2000, 1, 1, 0, 0, 479,2000, 1, 1,23,59],
|
488
|
-
[ 2000, 1, 2, 0, 0, 2000, 1, 1, 0, 0, 480,2000, 1, 2, 0, 0],
|
489
|
-
[ 2000, 1, 2, 0, 1, 2000, 1, 1, 0, 0, 480,2000, 1, 2, 0, 0],
|
490
|
-
[ 2010, 3,22, 6,11, 2000, 1, 1, 0, 0, 480,2000, 1, 2, 0, 0]
|
491
|
-
].each {|start_year, start_month, start_day, start_hour,start_min,
|
492
|
-
finish_year, finish_month, finish_day, finish_hour,finish_min,result,
|
493
|
-
y,m,d,h,n|
|
494
|
-
start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
|
495
|
-
finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
|
496
|
-
expected_date=DateTime.new(y,m,d,h,n)
|
497
|
-
duration, result_date=day.diff(start,finish)
|
498
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
499
|
-
assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
|
500
|
-
}
|
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
|
501
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
|
502
423
|
end
|
503
|
-
|
504
|
-
private
|
505
424
|
|
506
|
-
def
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
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
|
515
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
|
516
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
|
517
553
|
|
518
554
|
def clock(hour,min)
|
519
555
|
return Workpattern.clock(hour,min)
|