workpattern 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,186 +1,197 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- class TestWorkpattern < MiniTest::Unit::TestCase #:nodoc:
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(: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)
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
- mywp.resting(:start=>mydate1,:finish=>mydate2, :days =>:all, :from_time=>Workpattern.clock(0,0), :to_time=>Workpattern.clock(23,59))
22
+ mydate1 = Time.gm(2013, 9, 27, 0, 0, 0)
23
+ mydate2 = Time.gm(2013, 9, 27, 23, 59, 59)
21
24
 
22
- assert_equal 60, mywp.diff(DateTime.civil(2013,9,26,17,0),DateTime.civil(2013,9,27,10,0))
23
- end
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 DateTime.new(base), wp.from
34
- assert_equal DateTime.new(base+span-1,12,31,23,59), wp.to
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 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)
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(:days=>:all,:from_time=>clock(0,0),:to_time=>clock(0,0),:work_type=>1)
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(:days=>:all,:from_time=>clock(23,59),:to_time=>clock(23,59),:work_type=>1)
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(: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
-
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
- [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)
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=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)
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,-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)
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=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)
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
- [ 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
- }
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('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'
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=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))
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
- [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)
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(: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))
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| return obj}
262
- end
263
-
292
+ ss.each { |obj| return obj }
293
+ end
264
294
 
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
- }
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
- def clock(hour,min)
274
- return Workpattern.clock(hour,min)
303
+
304
+ def clock(hour, min)
305
+ Workpattern.clock(hour, min)
275
306
  end
276
307
  end