workpattern 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +4 -1
- data/.travis.yml +8 -2
- data/CHANGELOG +19 -0
- data/Gemfile +0 -0
- data/README.md +58 -57
- data/Rakefile +0 -0
- data/lib/workpattern.rb +65 -55
- data/lib/workpattern/clock.rb +17 -20
- data/lib/workpattern/utility/base.rb +16 -21
- data/lib/workpattern/version.rb +2 -2
- data/lib/workpattern/week.rb +266 -189
- data/lib/workpattern/workpattern.rb +170 -142
- data/script/console +0 -0
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- data/test/test_clock.rb +19 -22
- data/test/test_helper.rb +0 -0
- data/test/test_week.rb +393 -368
- data/test/test_workpattern.rb +238 -207
- data/test/test_workpattern_module.rb +57 -51
- data/workpattern.gemspec +7 -6
- metadata +44 -16
- data/config/website.yml +0 -2
data/test/test_workpattern.rb
CHANGED
@@ -1,186 +1,197 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class TestWorkpattern < MiniTest::
|
4
|
-
|
3
|
+
class TestWorkpattern < MiniTest::Test #:nodoc:
|
5
4
|
def setup
|
6
|
-
Workpattern.clear
|
5
|
+
Workpattern.clear
|
7
6
|
end
|
8
7
|
|
9
8
|
def test_can_diff_between_working_period_and_resting_day
|
10
9
|
# This is the test for issue 15
|
11
|
-
mywp=Workpattern.new('My Workpattern',2013,3)
|
12
|
-
mywp.resting(
|
13
|
-
mywp.resting(:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
mywp = Workpattern.new('My Workpattern', 2013, 3)
|
11
|
+
mywp.resting(days: :weekend)
|
12
|
+
mywp.resting(days: :weekday,
|
13
|
+
from_time: Workpattern.clock(0, 0),
|
14
|
+
to_time: Workpattern.clock(8, 59))
|
15
|
+
mywp.resting(days: :weekday,
|
16
|
+
from_time: Workpattern.clock(12, 0),
|
17
|
+
to_time: Workpattern.clock(12, 59))
|
18
|
+
mywp.resting(days: :weekday,
|
19
|
+
from_time: Workpattern.clock(18, 0),
|
20
|
+
to_time: Workpattern.clock(23, 59))
|
19
21
|
|
20
|
-
|
22
|
+
mydate1 = Time.gm(2013, 9, 27, 0, 0, 0)
|
23
|
+
mydate2 = Time.gm(2013, 9, 27, 23, 59, 59)
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
mywp.resting(start: mydate1, finish: mydate2, days: :all,
|
26
|
+
from_time: Workpattern.clock(0, 0),
|
27
|
+
to_time: Workpattern.clock(23, 59))
|
28
|
+
time_a = Time.gm(2013, 9, 26, 17, 0)
|
29
|
+
time_b = Time.gm(2013, 9, 27, 10, 0)
|
30
|
+
assert_equal 60, mywp.diff(time_a, time_b)
|
31
|
+
end
|
24
32
|
|
25
33
|
def test_must_create_a_working_workpattern
|
26
|
-
name='mywp'
|
27
|
-
base=2001
|
28
|
-
span=11
|
29
|
-
wp=Workpattern.new(name,base,span)
|
34
|
+
name = 'mywp'
|
35
|
+
base = 2001
|
36
|
+
span = 11
|
37
|
+
wp = Workpattern.new(name, base, span)
|
30
38
|
assert_equal name, wp.name
|
31
39
|
assert_equal base, wp.base
|
32
40
|
assert_equal span, wp.span
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
41
|
+
assert_equal Time.gm(base), wp.from
|
42
|
+
assert_equal Time.gm(base + span - 1, 12, 31, 23, 59), wp.to
|
35
43
|
end
|
36
|
-
|
44
|
+
|
37
45
|
def test_must_set_patterns_correctly
|
38
|
-
name='mypattern'
|
39
|
-
base=2000
|
40
|
-
span=11
|
41
|
-
wp=Workpattern.new(name,base,span)
|
42
|
-
|
43
|
-
start=clock(0,0)
|
44
|
-
finish=clock(8,59)
|
45
|
-
assert_equal
|
46
|
-
wp.workpattern(:
|
47
|
-
|
48
|
-
wp.
|
49
|
-
|
50
|
-
|
51
|
-
assert_equal
|
52
|
-
wp.workpattern(:
|
53
|
-
|
54
|
-
wp.
|
46
|
+
name = 'mypattern'
|
47
|
+
base = 2000
|
48
|
+
span = 11
|
49
|
+
wp = Workpattern.new(name, base, span)
|
50
|
+
|
51
|
+
start = clock(0, 0)
|
52
|
+
finish = clock(8, 59)
|
53
|
+
assert_equal 10_080, get_week(wp.weeks).week_total
|
54
|
+
wp.workpattern(days: :all, from_time: start,
|
55
|
+
to_time: finish, work_type: 0)
|
56
|
+
assert_equal 6_300, get_week(wp.weeks).week_total
|
57
|
+
wp.workpattern(days: :sun, from_time: start,
|
58
|
+
to_time: finish, work_type: 1)
|
59
|
+
assert_equal 6_840, get_week(wp.weeks).week_total
|
60
|
+
wp.workpattern(days: :mon, from_time: start,
|
61
|
+
to_time: finish, work_type: 1)
|
62
|
+
assert_equal 7_380, get_week(wp.weeks).week_total
|
63
|
+
wp.workpattern(days: :all, from_time: clock(18, 0),
|
64
|
+
to_time: clock(18, 19), work_type: 0)
|
65
|
+
assert_equal 7_240, get_week(wp.weeks).week_total
|
66
|
+
wp.workpattern(days: :all, from_time: clock(0, 0),
|
67
|
+
to_time: clock(23, 59), work_type: 0)
|
55
68
|
assert_equal 0, get_week(wp.weeks).week_total
|
56
|
-
wp.workpattern(:
|
69
|
+
wp.workpattern(days: :all, from_time: clock(0, 0),
|
70
|
+
to_time: clock(0, 0), work_type: 1)
|
57
71
|
assert_equal 7, get_week(wp.weeks).week_total
|
58
|
-
wp.workpattern(:
|
72
|
+
wp.workpattern(days: :all, from_time: clock(23, 59),
|
73
|
+
to_time: clock(23, 59), work_type: 1)
|
59
74
|
assert_equal 14, get_week(wp.weeks).week_total
|
60
|
-
wp.workpattern(:
|
61
|
-
|
62
|
-
wp.
|
63
|
-
|
64
|
-
|
75
|
+
wp.workpattern(days: :all, from_time: clock(0, 0),
|
76
|
+
to_time: clock(23, 59), work_type: 1)
|
77
|
+
assert_equal 10_080, get_week(wp.weeks).week_total
|
78
|
+
wp.workpattern(days: :weekend, from_time: clock(0, 0),
|
79
|
+
to_time: clock(23, 59), work_type: 0)
|
80
|
+
assert_equal 7_200, get_week(wp.weeks).week_total
|
65
81
|
end
|
66
|
-
|
82
|
+
|
67
83
|
def test_must_add_minutes_in_a_working_workpattern
|
68
|
-
name='mypattern'
|
69
|
-
base=1999
|
70
|
-
span=11
|
71
|
-
wp=Workpattern.new(name,base,span)
|
72
|
-
tests=[[2000,1,1,0,0,3,2000,1,1,0,3],
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
calc_test(wp,tests,clue)
|
84
|
+
name = 'mypattern'
|
85
|
+
base = 1999
|
86
|
+
span = 11
|
87
|
+
wp = Workpattern.new(name, base, span)
|
88
|
+
tests = [[2000, 1, 1, 0, 0, 3, 2000, 1, 1, 0, 3],
|
89
|
+
[2000, 1, 1, 23, 59, 0, 2000, 1, 1, 23, 59],
|
90
|
+
[2000, 1, 1, 23, 59, 1, 2000, 1, 2, 0, 0],
|
91
|
+
[2000, 1, 1, 23, 59, 2, 2000, 1, 2, 0, 1],
|
92
|
+
[2000, 1, 1, 9, 10, 33, 2000, 1, 1, 9, 43],
|
93
|
+
[2000, 1, 1, 9, 10, 60, 2000, 1, 1, 10, 10],
|
94
|
+
[2000, 1, 1, 9, 0, 931, 2000, 1, 2, 0, 31],
|
95
|
+
[2000, 1, 1, 0, 0, 3, 2000, 1, 1, 0, 3]]
|
96
|
+
clue = 'add minutes in a working workpattern'
|
97
|
+
calc_test(wp, tests, clue)
|
83
98
|
end
|
84
|
-
|
99
|
+
|
85
100
|
def test_must_add_minutes_in_a_resting_workpattern
|
86
|
-
name='mypattern'
|
87
|
-
base=1999
|
88
|
-
span=11
|
89
|
-
wp=Workpattern.new(name,base,span)
|
90
|
-
start=
|
91
|
-
finish=
|
92
|
-
wp.workpattern(:
|
93
|
-
tests=[[2000,1,1,0,0,3,2003,6,9,0,3],
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
calc_test(wp,tests,clue)
|
101
|
+
name = 'mypattern'
|
102
|
+
base = 1999
|
103
|
+
span = 11
|
104
|
+
wp = Workpattern.new(name, base, span)
|
105
|
+
start = Time.gm(1999, 6, 11, 0, 0)
|
106
|
+
finish = Time.gm(2003, 6, 8, 0, 0)
|
107
|
+
wp.workpattern(days: :all, start: start, finish: finish, work_type: 0)
|
108
|
+
tests = [[2000, 1, 1, 0, 0, 3, 2003, 6, 9, 0, 3],
|
109
|
+
[2000, 1, 1, 23, 59, 0, 2000, 1, 1, 23, 59],
|
110
|
+
[2000, 1, 1, 23, 59, 1, 2003, 6, 9, 0, 1],
|
111
|
+
[2000, 1, 1, 23, 59, 2, 2003, 6, 9, 0, 2],
|
112
|
+
[2000, 1, 1, 9, 10, 33, 2003, 6, 9, 0, 33],
|
113
|
+
[2000, 1, 1, 9, 10, 60, 2003, 6, 9, 1, 0],
|
114
|
+
[2000, 1, 1, 9, 0, 931, 2003, 6, 9, 15, 31],
|
115
|
+
[2000, 1, 1, 0, 0, 3, 2003, 6, 9, 0, 3]]
|
116
|
+
clue = 'add minutes in a resting workpattern'
|
117
|
+
calc_test(wp, tests, clue)
|
104
118
|
end
|
105
|
-
|
119
|
+
|
106
120
|
def test_must_add_minutes_in_a_patterned_workpattern
|
107
121
|
assert true
|
108
122
|
end
|
109
|
-
|
123
|
+
|
110
124
|
def test_must_subtract_minutes_in_a_working_workpattern
|
111
|
-
name='mypattern'
|
112
|
-
base=1999
|
113
|
-
span=11
|
114
|
-
wp=Workpattern.new(name,base,span)
|
115
|
-
tests=[[2000,1,1,0,0
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
calc_test(wp,tests,clue)
|
125
|
+
name = 'mypattern'
|
126
|
+
base = 1999
|
127
|
+
span = 11
|
128
|
+
wp = Workpattern.new(name, base, span)
|
129
|
+
tests = [[2000, 1, 1, 0, 0, -3, 1999, 12, 31, 23, 57],
|
130
|
+
[2000, 1, 1, 23, 59, 0, 2000, 1, 1, 23, 59],
|
131
|
+
[2000, 1, 1, 23, 59, -1, 2000, 1, 1, 23, 58],
|
132
|
+
[2000, 1, 1, 23, 59, -2, 2000, 1, 1, 23, 57],
|
133
|
+
[2000, 1, 1, 9, 10, -33, 2000, 1, 1, 8, 37],
|
134
|
+
[2000, 1, 1, 9, 10, -60, 2000, 1, 1, 8, 10],
|
135
|
+
[2000, 1, 1, 9, 0, -931, 1999, 12, 31, 17, 29],
|
136
|
+
[2000, 1, 1, 0, 0, -3, 1999, 12, 31, 23, 57]]
|
137
|
+
clue = 'subtract minutes in a working workpattern'
|
138
|
+
calc_test(wp, tests, clue)
|
126
139
|
end
|
127
|
-
|
140
|
+
|
128
141
|
def test_must_subtract_minutes_in_a_resting_workpattern
|
129
|
-
name='mypattern'
|
130
|
-
base=1999
|
131
|
-
span=11
|
132
|
-
wp=Workpattern.new(name,base,span)
|
133
|
-
start=
|
134
|
-
finish=
|
135
|
-
wp.workpattern(:
|
136
|
-
tests=[[2000,1,1,0,0
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
calc_test(wp,tests,clue)
|
142
|
+
name = 'mypattern'
|
143
|
+
base = 1999
|
144
|
+
span = 11
|
145
|
+
wp = Workpattern.new(name, base, span)
|
146
|
+
start = Time.gm(1999, 6, 11, 0, 0)
|
147
|
+
finish = Time.gm(2003, 6, 8, 0, 0)
|
148
|
+
wp.workpattern(days: :all, start: start, finish: finish, work_type: 0)
|
149
|
+
tests = [[2000, 1, 1, 0, 0, -3, 1999, 6, 10, 23, 57],
|
150
|
+
[2000, 1, 1, 23, 59, 0, 2000, 1, 1, 23, 59],
|
151
|
+
[2000, 1, 1, 23, 59, -1, 1999, 6, 10, 23, 59],
|
152
|
+
[2000, 1, 1, 23, 59, -2, 1999, 6, 10, 23, 58],
|
153
|
+
[2000, 1, 1, 9, 10, -33, 1999, 6, 10, 23, 27],
|
154
|
+
[2000, 1, 1, 9, 10, -60, 1999, 6, 10, 23, 0],
|
155
|
+
[2000, 1, 1, 9, 0, -931, 1999, 6, 10, 8, 29],
|
156
|
+
[2000, 1, 1, 0, 0, -3, 1999, 6, 10, 23, 57]]
|
157
|
+
clue = 'subtract minutes in a resting workpattern'
|
158
|
+
calc_test(wp, tests, clue)
|
147
159
|
end
|
148
|
-
|
160
|
+
|
149
161
|
def test_must_subtract_minutes_in_a_patterned_workpattern
|
150
162
|
assert true
|
151
163
|
end
|
152
|
-
|
153
|
-
|
164
|
+
|
154
165
|
def test_must_calculate_difference_between_dates_in_working_calender
|
155
|
-
name='mypattern'
|
156
|
-
base=1999
|
157
|
-
span=40
|
158
|
-
wp=Workpattern.new(name,base,span)
|
159
|
-
|
160
|
-
[
|
161
|
-
[
|
162
|
-
[
|
163
|
-
[
|
164
|
-
[
|
165
|
-
[
|
166
|
-
[
|
167
|
-
[
|
168
|
-
[
|
169
|
-
[
|
170
|
-
[
|
171
|
-
[
|
172
|
-
[
|
173
|
-
[
|
174
|
-
[
|
175
|
-
[
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
start=
|
180
|
-
finish=
|
181
|
-
duration,
|
182
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
183
|
-
|
166
|
+
name = 'mypattern'
|
167
|
+
base = 1999
|
168
|
+
span = 40
|
169
|
+
wp = Workpattern.new(name, base, span)
|
170
|
+
|
171
|
+
[[2012, 10, 1, 0, 0, 2012, 10, 1, 0, 0, 0],
|
172
|
+
[2012, 10, 1, 0, 0, 2012, 10, 1, 0, 1, 1],
|
173
|
+
[2012, 10, 1, 0, 50, 2012, 10, 1, 0, 59, 9],
|
174
|
+
[2012, 10, 1, 8, 50, 2012, 10, 1, 9, 0, 10],
|
175
|
+
[2012, 10, 1, 0, 0, 2012, 10, 1, 23, 59, 1_439],
|
176
|
+
[2012, 10, 1, 0, 0, 2012, 10, 2, 0, 0, 1_440],
|
177
|
+
[2012, 10, 1, 0, 0, 2012, 10, 2, 0, 1, 1_441],
|
178
|
+
[2012, 10, 1, 0, 0, 2013, 3, 22, 6, 11, 248_051],
|
179
|
+
[2012, 10, 1, 0, 1, 2012, 10, 1, 0, 0, 1],
|
180
|
+
[2012, 10, 1, 0, 59, 2012, 10, 1, 0, 50, 9],
|
181
|
+
[2012, 10, 1, 9, 0, 2012, 10, 1, 8, 50, 10],
|
182
|
+
[2012, 10, 1, 23, 59, 2012, 10, 1, 0, 0, 1_439],
|
183
|
+
[2012, 10, 2, 0, 0, 2012, 10, 1, 0, 0, 1_440],
|
184
|
+
[2012, 10, 2, 0, 1, 2012, 10, 1, 0, 0, 1_441],
|
185
|
+
[2013, 3, 22, 6, 11, 2012, 10, 1, 0, 0, 248_051],
|
186
|
+
[2012, 10, 2, 6, 11, 2012, 10, 4, 8, 9, 2_998]].each do
|
187
|
+
|s_year, s_month, s_day, s_hour, s_min,
|
188
|
+
f_year, f_month, f_day, f_hour, f_min,
|
189
|
+
result|
|
190
|
+
start = Time.gm(s_year, s_month, s_day, s_hour, s_min)
|
191
|
+
finish = Time.gm(f_year, f_month, f_day, f_hour, f_min)
|
192
|
+
duration, _result_date = wp.diff(start, finish)
|
193
|
+
assert_equal result, duration, "duration diff(#{start}, #{finish})"
|
194
|
+
end
|
184
195
|
end
|
185
196
|
|
186
197
|
def test_must_calculate_difference_between_minutes_in_resting_workpattern
|
@@ -188,35 +199,57 @@ class TestWorkpattern < MiniTest::Unit::TestCase #:nodoc:
|
|
188
199
|
end
|
189
200
|
|
190
201
|
def test_must_calculate_difference_between_minutes_in_pattern_workpattern
|
191
|
-
assert true
|
202
|
+
assert true
|
192
203
|
end
|
193
204
|
|
194
205
|
def test_must_follow_the_example_in_workpattern
|
195
|
-
mywp=Workpattern.new
|
196
|
-
mywp.resting
|
197
|
-
mywp.resting
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
206
|
+
mywp = Workpattern.new 'My Workpattern', 2011, 10
|
207
|
+
mywp.resting days: :weekend
|
208
|
+
mywp.resting days: :weekday,
|
209
|
+
from_time: Workpattern.clock(0, 0),
|
210
|
+
to_time: Workpattern.clock(8, 59)
|
211
|
+
mywp.resting days: :weekday,
|
212
|
+
from_time: Workpattern.clock(12, 0),
|
213
|
+
to_time: Workpattern.clock(12, 59)
|
214
|
+
mywp.resting days: :weekday,
|
215
|
+
from_time: Workpattern.clock(18, 0),
|
216
|
+
to_time: Workpattern.clock(23, 59)
|
217
|
+
mydate = Time.gm 2011, 9, 1, 9, 0
|
218
|
+
result_date = mywp.calc mydate, 1920 # => 6/9/11@18:00
|
219
|
+
assert_equal Time.gm(2011, 9, 6, 18, 0), result_date,
|
220
|
+
'example in workpattern'
|
221
|
+
assert_equal 1920, mywp.diff(mydate, result_date)
|
203
222
|
end
|
204
|
-
|
223
|
+
|
205
224
|
def test_must_calculate_across_week_patterns
|
206
|
-
name='mypattern'
|
207
|
-
base=2011
|
208
|
-
span=11
|
209
|
-
wp=Workpattern.new(name,base,span)
|
210
|
-
start=
|
211
|
-
finish=
|
212
|
-
wp.resting(:
|
213
|
-
wp.working(:
|
214
|
-
|
215
|
-
|
216
|
-
wp.working(:
|
217
|
-
|
218
|
-
|
219
|
-
wp.working(:
|
225
|
+
name = 'mypattern'
|
226
|
+
base = 2011
|
227
|
+
span = 11
|
228
|
+
wp = Workpattern.new(name, base, span)
|
229
|
+
start = Time.gm(2012, 9, 24, 0, 0)
|
230
|
+
finish = Time.gm(2012, 10, 14, 0, 0)
|
231
|
+
wp.resting(days: :all, start: start, finish: finish)
|
232
|
+
wp.working(days: :mon, start: start, finish: finish,
|
233
|
+
from_time: Workpattern.clock(1, 0),
|
234
|
+
to_time: Workpattern.clock(1, 59))
|
235
|
+
wp.working(days: :tue, start: start, finish: finish,
|
236
|
+
from_time: Workpattern.clock(2, 0),
|
237
|
+
to_time: Workpattern.clock(2, 59))
|
238
|
+
wp.working(days: :wed, start: start, finish: finish,
|
239
|
+
from_time: Workpattern.clock(3, 0),
|
240
|
+
to_time: Workpattern.clock(3, 59))
|
241
|
+
wp.working(days: :thu, start: start, finish: finish,
|
242
|
+
from_time: Workpattern.clock(4, 0),
|
243
|
+
to_time: Workpattern.clock(4, 59))
|
244
|
+
wp.working(days: :fri, start: start, finish: finish,
|
245
|
+
from_time: Workpattern.clock(5, 0),
|
246
|
+
to_time: Workpattern.clock(5, 59))
|
247
|
+
wp.working(days: :sat, start: start, finish: finish,
|
248
|
+
from_time: Workpattern.clock(6, 0),
|
249
|
+
to_time: Workpattern.clock(6, 59))
|
250
|
+
wp.working(days: :sun, start: start, finish: finish,
|
251
|
+
from_time: Workpattern.clock(0, 0),
|
252
|
+
to_time: Workpattern.clock(23, 59))
|
220
253
|
|
221
254
|
# Mon Tue Wed Thu Fri Sat Sun
|
222
255
|
# 24 25 26 27 28 29 30
|
@@ -230,47 +263,45 @@ class TestWorkpattern < MiniTest::Unit::TestCase #:nodoc:
|
|
230
263
|
# Sat 06:00 - 06:59
|
231
264
|
# Sun 00:00 - 23:59
|
232
265
|
#
|
233
|
-
tests=[[2012,10,1,1,0,1,2012,10,1,1,1],
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
calc_test(wp,tests,clue)
|
266
|
+
tests = [[2012, 10, 1, 1, 0, 1, 2012, 10, 1, 1, 1],
|
267
|
+
[2012, 10, 14, 23, 59, 1, 2012, 10, 15, 0, 0],
|
268
|
+
[2012, 10, 1, 1, 0, 60 * 60 + 1, 2012, 10, 15, 0, 1],
|
269
|
+
[2012, 10, 1, 2, 0, -1, 2012, 10, 1, 1, 59],
|
270
|
+
[2012, 10, 2, 3, 0, -61, 2012, 10, 1, 1, 59],
|
271
|
+
[2012, 9, 24, 1, 1, -2, 2012, 9, 23, 23, 59],
|
272
|
+
[2012, 10, 1, 1, 59, 61, 2012, 10, 2, 3, 0],
|
273
|
+
[2012, 10, 1, 1, 1, -1, 2012, 10, 1, 1, 0],
|
274
|
+
[2012, 10, 1, 1, 0, -1, 2012, 9, 30, 23, 59]]
|
275
|
+
clue = 'calculate across week patterns'
|
276
|
+
calc_test(wp, tests, clue)
|
245
277
|
end
|
246
|
-
|
278
|
+
|
247
279
|
def test_must_know_whether_a_time_is_working_or_resting
|
248
|
-
name='working?'
|
249
|
-
base=2011
|
250
|
-
span=11
|
251
|
-
wp=Workpattern.new(name,base,span)
|
252
|
-
wp.resting(:
|
253
|
-
assert wp.working?(
|
254
|
-
assert !wp.working?(
|
280
|
+
name = 'working?'
|
281
|
+
base = 2011
|
282
|
+
span = 11
|
283
|
+
wp = Workpattern.new(name, base, span)
|
284
|
+
wp.resting(to_time: Workpattern.clock(8, 59))
|
285
|
+
assert wp.working?(Time.gm(2012, 1, 1, 9, 0))
|
286
|
+
assert !wp.working?(Time.gm(2012, 1, 1, 8, 59))
|
255
287
|
end
|
256
|
-
|
257
|
-
|
288
|
+
|
258
289
|
private
|
259
|
-
|
290
|
+
|
260
291
|
def get_week(ss)
|
261
|
-
ss.each {|obj|
|
262
|
-
end
|
263
|
-
|
292
|
+
ss.each { |obj| return obj }
|
293
|
+
end
|
264
294
|
|
265
|
-
def calc_test(wp,tests,clue)
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
295
|
+
def calc_test(wp, tests, clue)
|
296
|
+
tests.each do |y, m, d, h, n, add, yr, mr, dr, hr, nr|
|
297
|
+
start_date = Time.gm(y, m, d, h, n)
|
298
|
+
result_date = wp.calc(start_date, add)
|
299
|
+
assert_equal Time.gm(yr, mr, dr, hr, nr), result_date,
|
300
|
+
"result date calc(#{start_date}, #{add}) for #{clue}"
|
301
|
+
end
|
272
302
|
end
|
273
|
-
|
274
|
-
|
303
|
+
|
304
|
+
def clock(hour, min)
|
305
|
+
Workpattern.clock(hour, min)
|
275
306
|
end
|
276
307
|
end
|