workpattern 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/.travis.yml +1 -1
- data/CHANGELOG +13 -1
- data/Gemfile.lock +1 -1
- data/lib/workpattern/hour.rb +24 -20
- data/lib/workpattern/version.rb +1 -1
- data/test/test_clock.rb +3 -3
- data/test/test_day.rb +325 -206
- data/test/test_helper.rb +1 -23
- data/test/test_hour.rb +365 -228
- data/test/test_week.rb +14 -14
- data/test/test_workpattern.rb +15 -15
- data/test/test_workpattern_module.rb +12 -12
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NDllNzljYmEyMzBiMjY3ZDIwYWNhMWE0YWQwNWUxNTMxZGQ3ZDQzNTdmNGU2
|
10
|
-
YWI1OGYwNDZiOTU2NWViZWZmYjRkZmQzY2I5NDg1ODhmNjhjOGUyYjUwMDFh
|
11
|
-
MzllYTIwNGQ3ODY4NTMxNWNmZTk1MDEwNjU2ZTlmNjliNjU2M2Y=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZjgwZmM2ZTU1YjE0MzhkYTVkYzU2MTU0YmRhOWZkYzIyZDdhNzZmNmY0MWI3
|
14
|
-
OWNkN2MwNmMzOWIxYjg1ODE5MDM3MzFhYWIzMTJjOTMwMjMwMzlkMWViZWU0
|
15
|
-
MTMzYWFmMzRiZWEzMzA1NmE3YTllMTBhMmJlMzA3ZmJkYWQ0YTg=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1bf0371cc0f47c34f3ab9e7e740975077e3edbf6
|
4
|
+
data.tar.gz: bbd957d3fb41cedd503146cc8bb870e34c023994
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc1f35fbb2e5a1cf1f0cdb357da3348343041f47b034d139f470590949116fb78e889c80798241f627f05a90259f6c99ea3c390969e6806d68756888faa992b8
|
7
|
+
data.tar.gz: 5f7cea5e6f7869a0da1a6cd9cdb92d9836867567514709b0a1792b6438976705d0c500c5584c9f21714475b1ef6082a9aed8ae95a8c3da4ae07b9f60188b499c
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
+
## Workpattern v0.3.4 (Sep 23, 2013) ##
|
2
|
+
|
3
|
+
* Failed to subtract 1 minute from end of resting hour (#12) * Barrie Callender *
|
4
|
+
* Failed to add minutes starting from a resting period in a patterned hour (#13) * Barrie Callender *
|
5
|
+
* Failed to subtract the exact amount of minutes from a patterned hour (#14) * Barrie Callender *
|
6
|
+
|
7
|
+
|
8
|
+
## Workpattern v0.3.3 (Aug 21, 2013) ##
|
9
|
+
|
10
|
+
* The two tests no longer fail with Ruby 2.0 (#11) * Barrie Callender *
|
11
|
+
|
12
|
+
|
1
13
|
## Workpattern v0.3.2 (Mar 14, 2013) ##
|
2
14
|
|
3
|
-
* Changed methods on Hour module so as to not clash with Rails (#10) * Barrie Callender *
|
15
|
+
* Changed methods on Hour module so as to not clash with Rails (#10) * Barrie Callender *
|
4
16
|
* Applied DRY principle to workpattern method in Workpattern class * Barrie Callender *
|
5
17
|
* Removed file from emacs backup * Barrie Callender *
|
6
18
|
|
data/Gemfile.lock
CHANGED
data/lib/workpattern/hour.rb
CHANGED
@@ -20,7 +20,7 @@ module Workpattern
|
|
20
20
|
# @param [Integer] finish minute at end of range
|
21
21
|
# @param [Integer] type defines whether working (1) or resting (0)
|
22
22
|
#
|
23
|
-
def wp_workpattern(start,finish,type)
|
23
|
+
def wp_workpattern(start,finish,type=1)
|
24
24
|
return wp_working(start,finish) if type==1
|
25
25
|
return wp_resting(start,finish) if type==0
|
26
26
|
end
|
@@ -60,7 +60,6 @@ module Workpattern
|
|
60
60
|
# @return [Integer] number of minutes from <tt>start</tt> to <tt>finish</tt> inclusive
|
61
61
|
#
|
62
62
|
def wp_minutes(start,finish)
|
63
|
-
start,finish=finish,start if start > finish
|
64
63
|
return (self & wp_mask(start,finish)).to_s(2).count('1')
|
65
64
|
end
|
66
65
|
|
@@ -73,14 +72,9 @@ module Workpattern
|
|
73
72
|
# @return [DateTime,Integer,Boolean] The <tt>DateTime</tt> calculated along with remaining minutes and a flag indicating if starting point is next hour
|
74
73
|
#
|
75
74
|
def wp_calc(time,duration,next_hour=false)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
elsif (duration>0)
|
80
|
-
return wp_add(time,duration)
|
81
|
-
else
|
82
|
-
return time,duration
|
83
|
-
end
|
75
|
+
return wp_subtract(time,duration, next_hour) if duration < 0
|
76
|
+
return wp_add(time,duration) if duration > 0
|
77
|
+
return time,duration
|
84
78
|
end
|
85
79
|
|
86
80
|
# Returns the number of minutes between two minutes
|
@@ -133,16 +127,13 @@ module Workpattern
|
|
133
127
|
start = time.min
|
134
128
|
available_minutes=wp_minutes(start,59)
|
135
129
|
|
136
|
-
if
|
130
|
+
if not_enough_minutes duration, available_minutes
|
137
131
|
result_date = time + HOUR - (MINUTE*start)
|
138
132
|
result_remainder = duration-available_minutes
|
139
|
-
elsif (
|
140
|
-
result_date = time - (MINUTE*start) + last + 1
|
141
|
-
result_remainder = 0
|
142
|
-
elsif (wp_minutes(start,start+duration-1)==duration)
|
133
|
+
elsif exact_amount_of_minutes(start,duration)
|
143
134
|
result_date = time + (MINUTE*duration)
|
144
135
|
result_remainder = 0
|
145
|
-
else
|
136
|
+
else # more than enough minutes
|
146
137
|
step = start + duration
|
147
138
|
duration-=wp_minutes(start,step)
|
148
139
|
until (duration==0)
|
@@ -150,7 +141,7 @@ module Workpattern
|
|
150
141
|
duration-=wp_minutes(step,step)
|
151
142
|
end
|
152
143
|
step+=1
|
153
|
-
result_date = time + (MINUTE*step)
|
144
|
+
result_date = time - (MINUTE*time.min) + (MINUTE*step)
|
154
145
|
result_remainder = 0
|
155
146
|
end
|
156
147
|
return result_date, result_remainder
|
@@ -169,17 +160,18 @@ module Workpattern
|
|
169
160
|
time=time+(MINUTE*59)
|
170
161
|
return wp_calc(time,duration)
|
171
162
|
end
|
163
|
+
return time, duration if wp_total==0
|
172
164
|
else
|
173
165
|
start=time.min
|
174
166
|
available_minutes=0
|
175
167
|
available_minutes = wp_minutes(0,start-1) if start > 0
|
176
168
|
end
|
177
169
|
|
178
|
-
if
|
170
|
+
if not_enough_minutes duration,available_minutes
|
179
171
|
result_date = time - (MINUTE*start)
|
180
172
|
result_remainder = duration+available_minutes
|
181
|
-
elsif
|
182
|
-
result_date = time
|
173
|
+
elsif duration.abs==available_minutes
|
174
|
+
result_date = time - (MINUTE*(start-wp_first))
|
183
175
|
result_remainder = 0
|
184
176
|
else
|
185
177
|
step = start + duration
|
@@ -194,6 +186,18 @@ module Workpattern
|
|
194
186
|
return result_date, result_remainder
|
195
187
|
|
196
188
|
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def not_enough_minutes(duration,available_minutes)
|
193
|
+
return true if (duration.abs-available_minutes)>0
|
194
|
+
return false
|
195
|
+
end
|
196
|
+
|
197
|
+
def exact_amount_of_minutes(start,duration)
|
198
|
+
return true if wp_minutes(start,start+duration-1)==duration
|
199
|
+
false
|
200
|
+
end
|
197
201
|
end
|
198
202
|
end
|
199
203
|
|
data/lib/workpattern/version.rb
CHANGED
data/test/test_clock.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class TestClock <
|
3
|
+
class TestClock < MiniTest::Unit::TestCase #:nodoc:
|
4
4
|
|
5
5
|
def setup
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
def test_must_create_midnight_default
|
9
9
|
clock=Workpattern::Clock.new()
|
10
10
|
|
11
11
|
assert_equal 0, clock.minutes, "total default minutes"
|
@@ -17,7 +17,7 @@ class TestClock < Test::Unit::TestCase #:nodoc:
|
|
17
17
|
assert_equal 0, time.min, "minute in the day must be zero"
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_must_account_for_out_of_range_values
|
21
21
|
clock=Workpattern::Clock.new(27,80)
|
22
22
|
|
23
23
|
assert_equal 1700, clock.minutes, "total minutes"
|
data/test/test_day.rb
CHANGED
@@ -1,234 +1,353 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class TestDay <
|
3
|
+
class TestDay < MiniTest::Unit::TestCase #:nodoc:
|
4
4
|
|
5
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)
|
6
13
|
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
working_day = Workpattern::Day.new(1)
|
11
|
-
assert_equal 1440, working_day.total,"24 hour working total minutes"
|
15
|
+
def test_must_create_a_working_day
|
16
|
+
assert_equal 1440, @working_day.total,"24 hour working total minutes"
|
12
17
|
end
|
13
18
|
|
14
|
-
|
15
|
-
|
16
|
-
resting_day = Workpattern::Day.new(0)
|
17
|
-
assert_equal 0, resting_day.total,"24 hour resting total minutes"
|
19
|
+
def test_must_ceate_a_resting_day
|
20
|
+
assert_equal 0, @resting_day.total,"24 hour resting total minutes"
|
18
21
|
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
[12,0,12,59],
|
25
|
-
[17,0,22,59]
|
26
|
-
].each {|start_hour,start_min,finish_hour,finish_min|
|
27
|
-
times<<[clock(start_hour,start_min),clock(finish_hour,finish_min)]
|
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"
|
28
27
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
45
|
}
|
42
46
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
[2000,1 ,1 ,9 ,10,33 ,2000,1 ,1 ,9 ,43,0 ,false ,false],
|
55
|
-
[2000,1 ,1 ,9 ,10,60 ,2000,1 ,1 ,10,10,0 ,false ,false],
|
56
|
-
[2000,1 ,1 ,9 , 0,931 ,2000,1 ,2 ,0 ,0 ,31 ,false ,false]
|
57
|
-
]
|
58
|
-
clue="duplicate working pattern"
|
59
|
-
calc_test(new_day,tests,clue)
|
60
|
-
|
61
|
-
day = Workpattern::Day.new(0)
|
62
|
-
new_day=day.duplicate
|
63
|
-
assert_equal 0, new_day.total,"24 hour resting total minutes"
|
64
|
-
# y m ,d ,h ,n ,dur ,yr ,mr,dr,hr,nr,rem ,midnight, midnightr
|
65
|
-
tests=[
|
66
|
-
[2000,1,1,0,0,3,2000,1,2,0,0,3,false,false],
|
67
|
-
[2000,1,1,23,59,0,2000,1,1,23,59,0,false,false],
|
68
|
-
[2000,1,1,23,59,1,2000,1,2,0,0,1,false,false],
|
69
|
-
[2000,1,1,23,59,2,2000,1,2,0,0,2,false,false],
|
70
|
-
[2000,1,1,9,10,33,2000,1,2,0,0,33,false,false],
|
71
|
-
[2000,1,1,9,10,60,2000,1,2,0,0,60,false,false],
|
72
|
-
[2000,1,1,9,0,931,2000,1,2,0,0,931,false,false]
|
73
|
-
]
|
74
|
-
clue="duplicate resting pattern"
|
75
|
-
calc_test(new_day,tests,clue)
|
76
|
-
|
77
|
-
|
78
|
-
times=Array.new()
|
79
|
-
[[0,0,8,59],
|
80
|
-
[12,0,12,59],
|
81
|
-
[17,0,22,59]
|
82
|
-
].each {|start_hour,start_min,finish_hour,finish_min|
|
83
|
-
times<<[Workpattern::Clock.new(start_hour,start_min),Workpattern::Clock.new(finish_hour,finish_min)]
|
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
|
84
58
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
assert_equal total,new_day.total, "#{hours_in_day} hour total working minutes"
|
95
|
-
assert_equal first_time.hour, new_day.first_hour, "#{hours_in_day} hour first hour of the day"
|
96
|
-
assert_equal first_time.min, new_day.first_min, "#{hours_in_day} hour first minute of the day"
|
97
|
-
assert_equal last_time.hour, new_day.last_hour, "#{hours_in_day} hour last hour of the day"
|
98
|
-
assert_equal last_time.min, new_day.last_min, "#{hours_in_day} hour last minute of the day"
|
99
|
-
|
100
|
-
new_day.workpattern(clock(13,0),clock(13,0),0)
|
101
|
-
|
102
|
-
assert_equal total,day.total, "#{hours_in_day} hour total original working minutes"
|
103
|
-
|
104
|
-
assert_equal total-1,new_day.total, "#{hours_in_day} hour total new working minutes"
|
105
|
-
|
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"
|
106
67
|
}
|
107
|
-
|
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
|
+
|
108
75
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
[2000,1,1,0,0,3,2000,1,1,0,3,0,false,false],
|
116
|
-
[2000,1,1,0,0,0,2000,1,1,0,0,0,false,false],
|
117
|
-
[2000,1,1,0,59,0,2000,1,1,0,59,0,false,false],
|
118
|
-
[2000,1,1,0,11,3,2000,1,1,0,14,0,false,false],
|
119
|
-
[2000,1,1,0,0,60,2000,1,1,1,0,0,false,false],
|
120
|
-
[2000,1,1,0,0,61,2000,1,1,1,1,0,false,false],
|
121
|
-
[2000,1,1,0,30,60,2000,1,1,1,30,0,false,false],
|
122
|
-
[2000,12,31,23,59,1,2001,1,1,0,0,0,false,false],
|
123
|
-
[2000,1,1,9,10,33,2000,1,1,9,43,0,false,false],
|
124
|
-
[2000,1,1,9,10,60,2000,1,1,10,10,0,false,false],
|
125
|
-
[2000,1,1,9,0,931,2000,1,2,0,0,31,false,false]
|
126
|
-
]
|
127
|
-
clue = "add minutes in a working day"
|
128
|
-
calc_test(day,tests,clue)
|
129
|
-
|
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
|
130
82
|
end
|
131
|
-
|
132
|
-
must 'add minutes in a resting day' do
|
133
83
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
147
117
|
end
|
148
118
|
|
149
|
-
|
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
|
150
132
|
|
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
|
-
|
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
|
179
180
|
end
|
180
181
|
|
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
|
182
188
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
205
243
|
end
|
206
244
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
]
|
227
|
-
clue="subtract minutes in a resting day"
|
228
|
-
calc_test(day,tests,clue)
|
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
|
229
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
|
+
############################################################################
|
347
|
+
############################################################################
|
348
|
+
############################################################################
|
230
349
|
|
231
|
-
|
350
|
+
def test_must_subtract_minutes_in_a_patterned_day
|
232
351
|
|
233
352
|
day = Workpattern::Day.new(1)
|
234
353
|
[[0,0,8,59],
|
@@ -274,7 +393,7 @@ class TestDay < Test::Unit::TestCase #:nodoc:
|
|
274
393
|
end
|
275
394
|
|
276
395
|
|
277
|
-
|
396
|
+
def test_must_calculate_difference_between_times_in_working_day
|
278
397
|
day = Workpattern::Day.new(1)
|
279
398
|
|
280
399
|
[
|
@@ -305,7 +424,7 @@ class TestDay < Test::Unit::TestCase #:nodoc:
|
|
305
424
|
}
|
306
425
|
end
|
307
426
|
|
308
|
-
|
427
|
+
def test_must_calculate_difference_between_times_in_resting_day
|
309
428
|
day = Workpattern::Day.new(0)
|
310
429
|
|
311
430
|
[
|
@@ -336,7 +455,7 @@ class TestDay < Test::Unit::TestCase #:nodoc:
|
|
336
455
|
}
|
337
456
|
end
|
338
457
|
|
339
|
-
|
458
|
+
def test_must_calculate_difference_between_times_in_pattern_day
|
340
459
|
|
341
460
|
day = Workpattern::Day.new(1)
|
342
461
|
[[0,0,8,59],
|