workpattern 0.3.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +8 -4
- data/.travis.yml +18 -3
- data/CHANGELOG.md +88 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -4
- data/LICENSE.txt +21 -0
- data/README.md +56 -80
- data/Rakefile +9 -0
- data/lib/workpattern.rb +31 -91
- data/lib/workpattern/clock.rb +21 -20
- data/lib/workpattern/constants.rb +72 -0
- data/lib/workpattern/day.rb +211 -290
- data/lib/workpattern/version.rb +2 -4
- data/lib/workpattern/week.rb +239 -321
- data/lib/workpattern/week_pattern.rb +144 -0
- data/lib/workpattern/workpattern.rb +156 -187
- data/workpattern.gemspec +32 -18
- metadata +40 -28
- data/CHANGELOG +0 -35
- data/config/website.yml +0 -2
- data/lib/workpattern/hour.rb +0 -209
- data/lib/workpattern/utility/base.rb +0 -32
- data/test/test_clock.rb +0 -31
- data/test/test_day.rb +0 -522
- data/test/test_helper.rb +0 -3
- data/test/test_hour.rb +0 -389
- data/test/test_week.rb +0 -362
- data/test/test_workpattern.rb +0 -276
- data/test/test_workpattern_module.rb +0 -93
data/test/test_workpattern.rb
DELETED
@@ -1,276 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestWorkpattern < MiniTest::Unit::TestCase #:nodoc:
|
4
|
-
|
5
|
-
def setup
|
6
|
-
Workpattern.clear()
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_can_diff_between_working_period_and_resting_day
|
10
|
-
# This is the test for issue 15
|
11
|
-
mywp=Workpattern.new('My Workpattern',2013,3)
|
12
|
-
mywp.resting(:days => :weekend)
|
13
|
-
mywp.resting(:days =>:weekday, :from_time=>Workpattern.clock(0,0),:to_time=>Workpattern.clock(8,59))
|
14
|
-
mywp.resting(:days =>:weekday, :from_time=>Workpattern.clock(12,0),:to_time=>Workpattern.clock(12,59))
|
15
|
-
mywp.resting(:days =>:weekday, :from_time=>Workpattern.clock(18,0),:to_time=>Workpattern.clock(23,59))
|
16
|
-
|
17
|
-
mydate1=DateTime.civil(2013,9,27,0,0,0)
|
18
|
-
mydate2=DateTime.civil(2013,9,27,23,59,59)
|
19
|
-
|
20
|
-
mywp.resting(:start=>mydate1,:finish=>mydate2, :days =>:all, :from_time=>Workpattern.clock(0,0), :to_time=>Workpattern.clock(23,59))
|
21
|
-
|
22
|
-
assert_equal 60, mywp.diff(DateTime.civil(2013,9,26,17,0),DateTime.civil(2013,9,27,10,0))
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_must_create_a_working_workpattern
|
26
|
-
name='mywp'
|
27
|
-
base=2001
|
28
|
-
span=11
|
29
|
-
wp=Workpattern.new(name,base,span)
|
30
|
-
assert_equal name, wp.name
|
31
|
-
assert_equal base, wp.base
|
32
|
-
assert_equal span, wp.span
|
33
|
-
assert_equal DateTime.new(base), wp.from
|
34
|
-
assert_equal DateTime.new(base+span-1,12,31,23,59), wp.to
|
35
|
-
end
|
36
|
-
|
37
|
-
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 10080, get_week(wp.weeks).week_total
|
46
|
-
wp.workpattern(:days=>:all,:from_time=>start,:to_time=>finish,:work_type=>0)
|
47
|
-
assert_equal 6300, get_week(wp.weeks).week_total
|
48
|
-
wp.workpattern(:days=>:sun,:from_time=>start,:to_time=>finish,:work_type=>1)
|
49
|
-
assert_equal 6840, get_week(wp.weeks).week_total
|
50
|
-
wp.workpattern(:days=>:mon,:from_time=>start,:to_time=>finish,:work_type=>1)
|
51
|
-
assert_equal 7380, get_week(wp.weeks).week_total
|
52
|
-
wp.workpattern(:days=>:all,:from_time=>clock(18,0),:to_time=>clock(18,19),:work_type=>0)
|
53
|
-
assert_equal 7240, get_week(wp.weeks).week_total
|
54
|
-
wp.workpattern(:days=>:all,:from_time=>clock(0,0),:to_time=>clock(23,59),:work_type=>0)
|
55
|
-
assert_equal 0, get_week(wp.weeks).week_total
|
56
|
-
wp.workpattern(:days=>:all,:from_time=>clock(0,0),:to_time=>clock(0,0),:work_type=>1)
|
57
|
-
assert_equal 7, get_week(wp.weeks).week_total
|
58
|
-
wp.workpattern(:days=>:all,:from_time=>clock(23,59),:to_time=>clock(23,59),:work_type=>1)
|
59
|
-
assert_equal 14, get_week(wp.weeks).week_total
|
60
|
-
wp.workpattern(:days=>:all,:from_time=>clock(0,0),:to_time=>clock(23,59),:work_type=>1)
|
61
|
-
assert_equal 10080, get_week(wp.weeks).week_total
|
62
|
-
wp.workpattern(:days=>:weekend,:from_time=>clock(0,0),:to_time=>clock(23,59),:work_type=>0)
|
63
|
-
assert_equal 7200, get_week(wp.weeks).week_total
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
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
|
-
[2000,1,1,23,59,0,2000,1,1,23,59],
|
74
|
-
[2000,1,1,23,59,1,2000,1,2,0,0],
|
75
|
-
[2000,1,1,23,59,2,2000,1,2,0,1],
|
76
|
-
[2000,1,1,9,10,33,2000,1,1,9,43],
|
77
|
-
[2000,1,1,9,10,60,2000,1,1,10,10],
|
78
|
-
[2000,1,1,9,0,931,2000,1,2,0,31],
|
79
|
-
[2000,1,1,0,0,3,2000,1,1,0,3]
|
80
|
-
]
|
81
|
-
clue="add minutes in a working workpattern"
|
82
|
-
calc_test(wp,tests,clue)
|
83
|
-
end
|
84
|
-
|
85
|
-
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=DateTime.new(1999,6,11,0,0)
|
91
|
-
finish=DateTime.new(2003,6,8,0,0)
|
92
|
-
wp.workpattern(:days=>:all,:start=> start, :finish=>finish, :work_type=>0 )
|
93
|
-
tests=[[2000,1,1,0,0,3,2003,6,9,0,3],
|
94
|
-
[2000,1,1,23,59,0,2000,1,1,23,59],
|
95
|
-
[2000,1,1,23,59,1,2003,6,9,0,1],
|
96
|
-
[2000,1,1,23,59,2,2003,6,9,0,2],
|
97
|
-
[2000,1,1,9,10,33,2003,6,9,0,33],
|
98
|
-
[2000,1,1,9,10,60,2003,6,9,1,0],
|
99
|
-
[2000,1,1,9,0,931,2003,6,9,15,31],
|
100
|
-
[2000,1,1,0,0,3,2003,6,9,0,3]
|
101
|
-
]
|
102
|
-
clue="add minutes in a resting workpattern"
|
103
|
-
calc_test(wp,tests,clue)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_must_add_minutes_in_a_patterned_workpattern
|
107
|
-
assert true
|
108
|
-
end
|
109
|
-
|
110
|
-
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,-3,1999,12,31,23,57],
|
116
|
-
[2000,1,1,23,59,0,2000,1,1,23,59],
|
117
|
-
[2000,1,1,23,59,-1,2000,1,1,23,58],
|
118
|
-
[2000,1,1,23,59,-2,2000,1,1,23,57],
|
119
|
-
[2000,1,1,9,10,-33,2000,1,1,8,37],
|
120
|
-
[2000,1,1,9,10,-60,2000,1,1,8,10],
|
121
|
-
[2000,1,1,9,0,-931,1999,12,31,17,29],
|
122
|
-
[2000,1,1,0,0,-3,1999,12,31,23,57]
|
123
|
-
]
|
124
|
-
clue="subtract minutes in a working workpattern"
|
125
|
-
calc_test(wp,tests,clue)
|
126
|
-
end
|
127
|
-
|
128
|
-
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=DateTime.new(1999,6,11,0,0)
|
134
|
-
finish=DateTime.new(2003,6,8,0,0)
|
135
|
-
wp.workpattern(:days=>:all,:start=> start, :finish=>finish, :work_type=>0 )
|
136
|
-
tests=[[2000,1,1,0,0,-3,1999,6,10,23,57],
|
137
|
-
[2000,1,1,23,59,0,2000,1,1,23,59],
|
138
|
-
[2000,1,1,23,59,-1,1999,6,10,23,59],
|
139
|
-
[2000,1,1,23,59,-2,1999,6,10,23,58],
|
140
|
-
[2000,1,1,9,10,-33,1999,6,10,23,27],
|
141
|
-
[2000,1,1,9,10,-60,1999,6,10,23,0],
|
142
|
-
[2000,1,1,9,0,-931,1999,6,10,8,29],
|
143
|
-
[2000,1,1,0,0,-3,1999,6,10,23,57]
|
144
|
-
]
|
145
|
-
clue="subtract minutes in a resting workpattern"
|
146
|
-
calc_test(wp,tests,clue)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_must_subtract_minutes_in_a_patterned_workpattern
|
150
|
-
assert true
|
151
|
-
end
|
152
|
-
|
153
|
-
|
154
|
-
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
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 0, 0],
|
162
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1, 0, 1, 1],
|
163
|
-
[ 2012,10, 1, 0,50, 2012,10, 1, 0,59, 9],
|
164
|
-
[ 2012,10, 1, 8,50, 2012,10, 1, 9, 0, 10],
|
165
|
-
[ 2012,10, 1, 0, 0, 2012,10, 1,23,59, 1439],
|
166
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 0, 1440],
|
167
|
-
[ 2012,10, 1, 0, 0, 2012,10, 2, 0, 1, 1441],
|
168
|
-
[ 2012,10, 1, 0, 0, 2013, 3,22, 6,11,248051],
|
169
|
-
[ 2012,10, 1, 0, 1, 2012,10, 1, 0, 0, 1],
|
170
|
-
[ 2012,10, 1, 0,59, 2012,10, 1, 0,50, 9],
|
171
|
-
[ 2012,10, 1, 9, 0, 2012,10, 1, 8,50, 10],
|
172
|
-
[ 2012,10, 1,23,59, 2012,10, 1, 0, 0, 1439],
|
173
|
-
[ 2012,10, 2, 0, 0, 2012,10, 1, 0, 0, 1440],
|
174
|
-
[ 2012,10, 2, 0, 1, 2012,10, 1, 0, 0, 1441],
|
175
|
-
[ 2013, 3,22, 6,11, 2012,10, 1, 0, 0,248051],
|
176
|
-
[ 2012,10, 2, 6,11, 2012,10, 4, 8, 9, 2998]
|
177
|
-
].each {|start_year, start_month, start_day, start_hour,start_min,
|
178
|
-
finish_year, finish_month, finish_day, finish_hour,finish_min,result|
|
179
|
-
start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
|
180
|
-
finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
|
181
|
-
duration, result_date=wp.diff(start,finish)
|
182
|
-
assert_equal result, duration,"duration diff(#{start}, #{finish})"
|
183
|
-
}
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_must_calculate_difference_between_minutes_in_resting_workpattern
|
187
|
-
assert true
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_must_calculate_difference_between_minutes_in_pattern_workpattern
|
191
|
-
assert true
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_must_follow_the_example_in_workpattern
|
195
|
-
mywp=Workpattern.new('My Workpattern',2011,10)
|
196
|
-
mywp.resting(:days => :weekend)
|
197
|
-
mywp.resting(:days =>:weekday, :from_time=>Workpattern.clock(0,0),:to_time=>Workpattern.clock(8,59))
|
198
|
-
mywp.resting(:days =>:weekday, :from_time=>Workpattern.clock(12,0),:to_time=>Workpattern.clock(12,59))
|
199
|
-
mywp.resting(:days =>:weekday, :from_time=>Workpattern.clock(18,0),:to_time=>Workpattern.clock(23,59))
|
200
|
-
mydate=DateTime.civil(2011,9,1,9,0)
|
201
|
-
result_date = mywp.calc(mydate,1920) # => 6/9/11@18:00
|
202
|
-
assert_equal DateTime.civil(2011,9,6,18,0), result_date, 'example in workpattern'
|
203
|
-
end
|
204
|
-
|
205
|
-
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=DateTime.new(2012,9,24,0,0)
|
211
|
-
finish=DateTime.new(2012,10,14,0,0)
|
212
|
-
wp.resting(:days =>:all,:start=> start, :finish=>finish)
|
213
|
-
wp.working(:days =>:mon,:start=> start, :finish=>finish, :from_time=>Workpattern.clock(1,0),:to_time=>Workpattern.clock(1,59))
|
214
|
-
wp.working(:days =>:tue,:start=> start, :finish=>finish, :from_time=>Workpattern.clock(2,0),:to_time=>Workpattern.clock(2,59))
|
215
|
-
wp.working(:days =>:wed,:start=> start, :finish=>finish, :from_time=>Workpattern.clock(3,0),:to_time=>Workpattern.clock(3,59))
|
216
|
-
wp.working(:days =>:thu,:start=> start, :finish=>finish, :from_time=>Workpattern.clock(4,0),:to_time=>Workpattern.clock(4,59))
|
217
|
-
wp.working(:days =>:fri,:start=> start, :finish=>finish, :from_time=>Workpattern.clock(5,0),:to_time=>Workpattern.clock(5,59))
|
218
|
-
wp.working(:days =>:sat,:start=> start, :finish=>finish, :from_time=>Workpattern.clock(6,0),:to_time=>Workpattern.clock(6,59))
|
219
|
-
wp.working(:days =>:sun,:start=> start, :finish=>finish, :from_time=>Workpattern.clock(0,0),:to_time=>Workpattern.clock(23,59))
|
220
|
-
|
221
|
-
# Mon Tue Wed Thu Fri Sat Sun
|
222
|
-
# 24 25 26 27 28 29 30
|
223
|
-
# 1 2 3 4 5 6 7
|
224
|
-
# 8 9 10 11 12 13 14
|
225
|
-
# Mon 01:00 - 01:59
|
226
|
-
# Tue 02:00 - 02:59
|
227
|
-
# Wed 03:00 - 03:59
|
228
|
-
# Thu 04:00 - 04:59
|
229
|
-
# Fri 05:00 - 05:59
|
230
|
-
# Sat 06:00 - 06:59
|
231
|
-
# Sun 00:00 - 23:59
|
232
|
-
#
|
233
|
-
tests=[[2012,10,1,1,0,1,2012,10,1,1,1],
|
234
|
-
[2012,10,14,23,59,1,2012,10,15,0,0],
|
235
|
-
[2012,10,1,1,0,60*60+1,2012,10,15,0,1],
|
236
|
-
[2012,10,1,2,0,-1,2012,10,1,1,59],
|
237
|
-
[2012,10,2,3,0,-61,2012,10,1,1,59],
|
238
|
-
[2012,9,24,1,1,-2,2012,9,23,23,59],
|
239
|
-
[2012,10,1,1,59,61,2012,10,2,3,0],
|
240
|
-
[2012,10,1,1,1,-1,2012,10,1,1,0],
|
241
|
-
[2012,10,1,1,0,-1,2012,9,30,23,59]
|
242
|
-
]
|
243
|
-
clue="calculate across week patterns"
|
244
|
-
calc_test(wp,tests,clue)
|
245
|
-
end
|
246
|
-
|
247
|
-
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(:to_time=>Workpattern.clock(8,59))
|
253
|
-
assert wp.working?(DateTime.new(2012,1,1,9,0))
|
254
|
-
assert !wp.working?(DateTime.new(2012,1,1,8,59))
|
255
|
-
end
|
256
|
-
|
257
|
-
|
258
|
-
private
|
259
|
-
|
260
|
-
def get_week(ss)
|
261
|
-
ss.each {|obj| return obj}
|
262
|
-
end
|
263
|
-
|
264
|
-
|
265
|
-
def calc_test(wp,tests,clue)
|
266
|
-
|
267
|
-
tests.each{|y,m,d,h,n,add,yr,mr,dr,hr,nr|
|
268
|
-
start_date=DateTime.new(y,m,d,h,n)
|
269
|
-
result_date = wp.calc(start_date,add)
|
270
|
-
assert_equal DateTime.new(yr,mr,dr,hr,nr), result_date, "result date calc(#{start_date},#{add}) for #{clue}"
|
271
|
-
}
|
272
|
-
end
|
273
|
-
def clock(hour,min)
|
274
|
-
return Workpattern.clock(hour,min)
|
275
|
-
end
|
276
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestWorkpatternModule < MiniTest::Unit::TestCase #:nodoc:
|
4
|
-
|
5
|
-
def setup
|
6
|
-
Workpattern.clear()
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_must_create_workpattern_with_given_name
|
10
|
-
|
11
|
-
wp = Workpattern.new()
|
12
|
-
assert_equal Workpattern::DEFAULT_WORKPATTERN_NAME, wp.name, 'not returned the default workpattern name'
|
13
|
-
assert_equal Workpattern::DEFAULT_BASE_YEAR, wp.from.year, 'not returned the default workpattern base year'
|
14
|
-
assert_equal Workpattern::DEFAULT_SPAN, wp.span, 'not returned the default workpattern span'
|
15
|
-
|
16
|
-
mywp_name='barrie callender'
|
17
|
-
mywp_base=1963
|
18
|
-
mywp_span=48
|
19
|
-
mywp = Workpattern.new(mywp_name, mywp_base,mywp_span)
|
20
|
-
assert_equal mywp_name, mywp.name, 'not returned the supplied workpattern name'
|
21
|
-
assert_equal mywp_base, mywp.from.year, 'not returned the supplied workpattern base year'
|
22
|
-
assert_equal mywp_span, mywp.span, 'not returned the supplied workpattern span'
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_must_raise_error_when_creating_workpattern_with_existing_name
|
27
|
-
|
28
|
-
assert_raises NameError do
|
29
|
-
mywp_name='duplicate'
|
30
|
-
wp=Workpattern.new(mywp_name)
|
31
|
-
wp=Workpattern.new(mywp_name)
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_must_return_an_array_of_all_known_workpattern_objects
|
37
|
-
|
38
|
-
names =%w{fred harry sally}
|
39
|
-
names.each {|name| wp=Workpattern.new(name)}
|
40
|
-
wp_names = Workpattern.to_a
|
41
|
-
|
42
|
-
assert_equal names.size, wp_names.size, "lists are not the same size"
|
43
|
-
|
44
|
-
wp_names.each {|name, wp| assert names.include?(name)}
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_must_return_empty_array_when_no_workpatterns_exist
|
48
|
-
|
49
|
-
assert Workpattern.to_a.empty?
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_must_return_existing_workpattern
|
53
|
-
|
54
|
-
names =%w{fred harry sally}
|
55
|
-
names.each {|name| wp=Workpattern.new(name)}
|
56
|
-
|
57
|
-
names.each {|name|
|
58
|
-
wp=Workpattern.get(name)
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_must_raise_error_when_workpattern_does_not_exist
|
63
|
-
|
64
|
-
names =%w{fred harry sally}
|
65
|
-
names.each {|name| wp=Workpattern.new(name)}
|
66
|
-
assert_raises NameError do
|
67
|
-
wp=Workpattern.get('missing')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_must_delete_existing_workpattern_returning_true
|
72
|
-
|
73
|
-
names =%w{fred harry sally}
|
74
|
-
names.each {|name| wp=Workpattern.new(name)}
|
75
|
-
names.each {|name| assert Workpattern.delete(name)}
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_must_return_false_deleting_workpattern_that_does_not_exist
|
79
|
-
names =%w{fred harry sally}
|
80
|
-
names.each {|name| wp=Workpattern.new(name)}
|
81
|
-
assert !Workpattern.delete('missing')
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_must_delete_all_workpatterns
|
85
|
-
|
86
|
-
names =%w{fred harry sally}
|
87
|
-
names.each {|name| wp=Workpattern.new(name)}
|
88
|
-
Workpattern.clear
|
89
|
-
assert Workpattern.to_a.empty?
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
end
|