workpattern 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
File without changes
File without changes
@@ -1,32 +1,29 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- class TestClock < MiniTest::Unit::TestCase #:nodoc:
4
-
3
+ class TestClock < MiniTest::Test #:nodoc:
5
4
  def setup
6
5
  end
7
-
6
+
8
7
  def test_must_create_midnight_default
9
- clock=Workpattern::Clock.new()
10
-
11
- assert_equal 0, clock.minutes, "total default minutes"
12
- assert_equal 0, clock.hour, "default hour is zero"
13
- assert_equal 0, clock.min, "default minute is zero"
8
+ clock = Workpattern::Clock.new
9
+
10
+ assert_equal 0, clock.minutes, 'total default minutes'
11
+ assert_equal 0, clock.hour, 'default hour is zero'
12
+ assert_equal 0, clock.min, 'default minute is zero'
14
13
  time = clock.time
15
- assert time.kind_of?(DateTime), "must return a DateTime object"
16
- assert_equal 0, time.hour, "hour in the day must be zero"
17
- assert_equal 0, time.min, "minute in the day must be zero"
14
+ assert time.is_a?(DateTime), 'must return a DateTime object'
15
+ assert_equal 0, time.hour, 'hour in the day must be zero'
16
+ assert_equal 0, time.min, 'minute in the day must be zero'
18
17
  end
19
-
18
+
20
19
  def test_must_account_for_out_of_range_values
21
- clock=Workpattern::Clock.new(27,80)
22
-
23
- assert_equal 1700, clock.minutes, "total minutes"
24
- assert_equal 4, clock.hour, "hour is 4"
25
- assert_equal 20, clock.min, "minute is 20"
20
+ clock = Workpattern::Clock.new(27, 80)
21
+
22
+ assert_equal 1700, clock.minutes, 'total minutes'
23
+ assert_equal 4, clock.hour, 'hour is 4'
24
+ assert_equal 20, clock.min, 'minute is 20'
26
25
  time = clock.time
27
- assert time.kind_of?(DateTime), "must return a DateTime object"
28
- assert_equal DateTime.new(1963,6,10,4,20), time
29
- assert_equal 4, time.hour, "hour in the day must be 4"
30
- assert_equal 20, time.min, "minute in the day must be 20"
26
+ assert time.is_a?(DateTime), 'must return a DateTime object'
27
+ assert_equal DateTime.new(1963, 6, 10, 4, 20), time
31
28
  end
32
- end
29
+ end
File without changes
@@ -1,507 +1,532 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- class TestWeek < MiniTest::Unit::TestCase #:nodoc:
4
-
3
+ class TestWeek < MiniTest::Test #:nodoc:
4
+ include Workpattern::Base
5
5
  def setup
6
- start=DateTime.new(2000,1,3)
7
- finish=DateTime.new(2000,1,9)
8
-
9
- @working_week=Workpattern::Week.new(start,finish,1)
10
-
11
- @resting_week=Workpattern::Week.new(start,finish,0)
12
-
13
- @pattern_week=Workpattern::Week.new(start,finish,1)
14
- @pattern_week.workpattern(:weekend,Workpattern.clock(0,0),Workpattern.clock(23,59),0)
15
- @pattern_week.workpattern(:weekday,Workpattern.clock(0,0),Workpattern.clock(8,59),0)
16
- @pattern_week.workpattern(:weekday,Workpattern.clock(12,30),Workpattern.clock(13,0),0)
17
- @pattern_week.workpattern(:weekday,Workpattern.clock(17,0),Workpattern.clock(23,59),0)
18
-
19
- end
20
-
21
-
22
- def test_must_create_a_working_week
23
- start=DateTime.new(2000,1,1,11,3)
24
- finish=DateTime.new(2005,12,31,16,41)
25
- working_week=week(start,finish,1)
26
- assert_equal DateTime.new(start.year,start.month,start.day), working_week.start
27
- assert_equal DateTime.new(finish.year,finish.month,finish.day), working_week.finish
28
- assert_equal 3156480, working_week.total #2192 days
29
- end
30
-
31
- def test_create_working_week_of_3_concecutive_days
32
- start=DateTime.new(2000,1,2,11,3) # Sunday
33
- finish=DateTime.new(2000,1,4,16,41) # Tuesday
34
- working_week=week(start,finish,1)
35
- assert_equal DateTime.new(start.year,start.month,start.day), working_week.start
36
- assert_equal DateTime.new(finish.year,finish.month,finish.day), working_week.finish
37
- assert_equal 1440 * 3, working_week.total #3 days
38
- end
39
-
40
- def test_create_working_week_f_to_Su
41
- start=DateTime.new(2000,1,7,11,3) # Friday
42
- finish=DateTime.new(2000,1,9,16,41) # Sunday
43
- working_week=week(start,finish,1)
44
- assert_equal DateTime.new(start.year,start.month,start.day), working_week.start
45
- assert_equal DateTime.new(finish.year,finish.month,finish.day), working_week.finish
46
- assert_equal 1440 * 3, working_week.total #3 days
47
- end
48
-
49
- def test_create_working_week_Th_to_Su
50
- start=DateTime.new(2000,1,6,11,3) # Thursday
51
- finish=DateTime.new(2000,1,8,16,41) # Sunday
52
- working_week=week(start,finish,1)
53
- assert_equal DateTime.new(start.year,start.month,start.day), working_week.start
54
- assert_equal DateTime.new(finish.year,finish.month,finish.day), working_week.finish
55
- assert_equal 1440 * 3, working_week.total #3 days
6
+ start = Time.gm(2000, 1, 3)
7
+ finish = Time.gm(2000, 1, 9)
8
+
9
+ @w_week = Workpattern::Week.new(start, finish, 1)
10
+
11
+ @r_week = Workpattern::Week.new(start, finish, 0)
12
+
13
+ @p_week = Workpattern::Week.new(start, finish, 1)
14
+ @p_week.workpattern(:weekend, Workpattern.clock(0, 0),
15
+ Workpattern.clock(23, 59), 0)
16
+ @p_week.workpattern(:weekday, Workpattern.clock(0, 0),
17
+ Workpattern.clock(8, 59), 0)
18
+ @p_week.workpattern(:weekday, Workpattern.clock(12, 30),
19
+ Workpattern.clock(13, 0), 0)
20
+ @p_week.workpattern(:weekday, Workpattern.clock(17, 0),
21
+ Workpattern.clock(23, 59), 0)
22
+ end
23
+
24
+ def test_must_create_a_w_week
25
+ start = Time.gm(2000, 1, 1, 11, 3)
26
+ finish = Time.gm(2005, 12, 31, 16, 41)
27
+ w_week = week(start, finish, 1)
28
+ assert_equal Time.gm(start.year, start.month, start.day),
29
+ w_week.start
30
+ assert_equal Time.gm(finish.year, finish.month, finish.day),
31
+ w_week.finish
32
+ assert_equal 3_156_480, w_week.total # 2192 days
33
+ end
34
+
35
+ def test_create_w_week_of_3_concecutive_days
36
+ start = Time.gm(2000, 1, 2, 11, 3) # Sunday
37
+ finish = Time.gm(2000, 1, 4, 16, 41) # Tuesday
38
+ w_week = week(start, finish, 1)
39
+ assert_equal Time.gm(start.year, start.month,
40
+ start.day), w_week.start
41
+ assert_equal Time.gm(finish.year, finish.month, finish.day),
42
+ w_week.finish
43
+ assert_equal 1_440 * 3, w_week.total # 3 days
44
+ end
45
+
46
+ def test_create_working_week_friday_to_sunday
47
+ start = Time.gm(2000, 1, 7, 11, 3) # Friday
48
+ finish = Time.gm(2000, 1, 9, 16, 41) # Sunday
49
+ w_week = week(start, finish, 1)
50
+ assert_equal Time.gm(start.year, start.month, start.day),
51
+ w_week.start
52
+ assert_equal Time.gm(finish.year, finish.month, finish.day),
53
+ w_week.finish
54
+ assert_equal 1_440 * 3, w_week.total # 3 days
55
+ end
56
+
57
+ def test_create_working_week_thursday_to_sunday
58
+ start = Time.gm(2000, 1, 6, 11, 3) # Thursday
59
+ finish = Time.gm(2000, 1, 8, 16, 41) # Sunday
60
+ w_week = week(start, finish, 1)
61
+ assert_equal Time.gm(start.year, start.month, start.day),
62
+ w_week.start
63
+ assert_equal Time.gm(finish.year, finish.month, finish.day),
64
+ w_week.finish
65
+ assert_equal 1_440 * 3, w_week.total # 3 days
56
66
  end
57
67
 
58
68
  def test_must_create_a_resting_week
59
- start=DateTime.new(2000,1,1,11,3)
60
- finish=DateTime.new(2005,12,31,16,41)
61
- resting_week=week(start,finish,0)
62
- assert_equal DateTime.new(start.year,start.month,start.day), resting_week.start
63
- assert_equal DateTime.new(finish.year,finish.month,finish.day), resting_week.finish
64
- assert_equal 0, resting_week.total#2192
65
- assert_equal 0,resting_week.week_total
69
+ start = Time.gm(2000, 1, 1, 11, 3)
70
+ finish = Time.gm(2005, 12, 31, 16, 41)
71
+ resting_week = week(start, finish, 0)
72
+ assert_equal Time.gm(start.year, start.month, start.day),
73
+ resting_week.start
74
+ assert_equal Time.gm(finish.year, finish.month, finish.day),
75
+ resting_week.finish
76
+ assert_equal 0, resting_week.total # 2192
77
+ assert_equal 0, resting_week.week_total
66
78
  end
67
79
 
68
80
  def test_must_duplicate_all_of_a_week
69
- start=DateTime.new(2000,1,1,11,3)
70
- finish=DateTime.new(2005,12,31,16,41)
71
- week=week(start,finish,1)
72
- new_week=week.duplicate
73
- assert_equal DateTime.new(start.year,start.month,start.day), new_week.start
74
- assert_equal DateTime.new(finish.year,finish.month,finish.day), new_week.finish
75
- assert_equal 3156480, new_week.total#2192
76
- week.workpattern(:weekend,Workpattern.clock(0,0),Workpattern.clock(23,59),0)
77
- assert_equal 3156480, new_week.total#2192
81
+ start = Time.gm(2000, 1, 1, 11, 3)
82
+ finish = Time.gm(2005, 12, 31, 16, 41)
83
+ week = week(start, finish, 1)
84
+ new_week = week.duplicate
85
+ assert_equal Time.gm(start.year, start.month, start.day),
86
+ new_week.start
87
+ assert_equal Time.gm(finish.year, finish.month, finish.day),
88
+ new_week.finish
89
+ assert_equal 3_156_480, new_week.total # 2192
90
+ week.workpattern(:weekend, Workpattern.clock(0, 0),
91
+ Workpattern.clock(23, 59), 0)
92
+ assert_equal 3_156_480, new_week.total # 2192
78
93
  end
79
94
 
80
95
  def test_must_set_week_pattern_correctly
81
- start=DateTime.new(2000,1,3)
82
- finish=DateTime.new(2000,1,9)
96
+ start = Time.gm(2000, 1, 3)
97
+ finish = Time.gm(2000, 1, 9)
83
98
 
84
- pattern_week=Workpattern::Week.new(start,finish,1)
99
+ pattern_week = Workpattern::Week.new(start, finish, 1)
85
100
  assert_equal start, pattern_week.start
86
101
  assert_equal finish, pattern_week.finish
87
- assert_equal 10080, pattern_week.week_total
88
- pattern_week.workpattern(:weekend,Workpattern.clock(0,0),Workpattern.clock(23,59),0)
89
- assert_equal 7200, pattern_week.week_total
90
- pattern_week.workpattern(:weekday,Workpattern.clock(0,0),Workpattern.clock(8,59),0)
91
- assert_equal 4500, pattern_week.week_total
92
- pattern_week.workpattern(:weekday,Workpattern.clock(12,30),Workpattern.clock(13,0),0)
93
- assert_equal 4345, pattern_week.week_total
94
- pattern_week.workpattern(:weekday,Workpattern.clock(17,0),Workpattern.clock(23,59),0)
95
- assert_equal 2245, pattern_week.week_total
102
+ assert_equal 10_080, pattern_week.week_total
103
+ pattern_week.workpattern(:weekend, Workpattern.clock(0, 0),
104
+ Workpattern.clock(23, 59), 0)
105
+ assert_equal 7_200, pattern_week.week_total
106
+ pattern_week.workpattern(:weekday, Workpattern.clock(0, 0),
107
+ Workpattern.clock(8, 59), 0)
108
+ assert_equal 4_500, pattern_week.week_total
109
+ pattern_week.workpattern(:weekday, Workpattern.clock(12, 30),
110
+ Workpattern.clock(13, 0), 0)
111
+ assert_equal 4_345, pattern_week.week_total
112
+ pattern_week.workpattern(:weekday, Workpattern.clock(17, 0),
113
+ Workpattern.clock(23, 59), 0)
114
+ assert_equal 2_245, pattern_week.week_total
96
115
  end
97
116
 
98
117
  def test_must_set_patterns_correctly
99
- start=DateTime.new(2000,1,1,0,0)
100
- finish=DateTime.new(2005,12,31,8,59)
101
- working_week=week(start,finish,1)
102
- assert_equal 10080, working_week.week_total
103
- working_week.workpattern(:all,start,finish,0)
104
- assert_equal 6300, working_week.week_total
105
- working_week.workpattern(:sun,start,finish,1)
106
- assert_equal 6840, working_week.week_total
107
- working_week.workpattern(:mon,start,finish,1)
108
- assert_equal 7380, working_week.week_total
109
- working_week.workpattern(:all,clock(18,0),clock(18,19),0)
110
- assert_equal 7240, working_week.week_total
111
- working_week.workpattern(:all,clock(0,0),clock(23,59),0)
112
- assert_equal 0, working_week.week_total
113
- working_week.workpattern(:all,clock(0,0),clock(0,0),1)
114
- assert_equal 7, working_week.week_total
115
- working_week.workpattern(:all,clock(23,59),clock(23,59),1)
116
- assert_equal 14, working_week.week_total
117
- working_week.workpattern(:all,clock(0,0),clock(23,59),1)
118
- assert_equal 10080, working_week.week_total
119
- working_week.workpattern(:weekend,clock(0,0),clock(23,59),0)
120
- assert_equal 7200, working_week.week_total
121
- end
122
-
123
- def test_must_add_minutes_in_a_working_week_result_in_same_day
124
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,3,7,31),29)
125
- assert_equal DateTime.new(2000,1,3,8,0), result_date
126
- refute midnight_flag
127
- assert_equal 0, result_duration
128
- end
129
-
130
- def test_must_add_minutes_in_a_working_week_result_in_next_day
131
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,3,7,31),990)
132
- assert_equal DateTime.new(2000,1,4,0,1), result_date
133
- refute midnight_flag
134
- assert_equal 0, result_duration
135
- end
136
-
137
- def test_must_add_minutes_in_a_working_week_result_in_later_day
138
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,3,7,31),2430)
139
- assert_equal DateTime.new(2000,1,5,0,1), result_date
140
- refute midnight_flag
141
- assert_equal 0, result_duration
142
- end
143
-
144
- def test_must_add_minutes_in_a_working_week_result_in_start_next_day
145
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,3,7,31),989)
146
- assert_equal DateTime.new(2000,1,4,0,0), result_date
147
- refute midnight_flag
148
- assert_equal 0, result_duration
149
- end
150
-
151
- def test_must_add_0_minutes_in_a_working_week
152
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,3,7,31),0)
153
- assert_equal DateTime.new(2000,1,3,7,31), result_date
154
- refute midnight_flag
155
- assert_equal 0, result_duration
156
- end
157
-
158
- def test_must_add_too_many_minutes_in_a_working_week
159
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,3,7,31),9630)
160
- assert_equal DateTime.new(2000,1,10,0,0), result_date
161
- refute midnight_flag
162
- assert_equal 1, result_duration
118
+ start = Time.gm(2000, 1, 1, 0, 0)
119
+ finish = Time.gm(2005, 12, 31, 8, 59)
120
+ w_week = week(start, finish, 1)
121
+ assert_equal 10_080, w_week.week_total
122
+ w_week.workpattern(:all, start, finish, 0)
123
+ assert_equal 6_300, w_week.week_total
124
+ w_week.workpattern(:sun, start, finish, 1)
125
+ assert_equal 6_840, w_week.week_total
126
+ w_week.workpattern(:mon, start, finish, 1)
127
+ assert_equal 7_380, w_week.week_total
128
+ w_week.workpattern(:all, clock(18, 0), clock(18, 19), 0)
129
+ assert_equal 7_240, w_week.week_total
130
+ w_week.workpattern(:all, clock(0, 0), clock(23, 59), 0)
131
+ assert_equal 0, w_week.week_total
132
+ w_week.workpattern(:all, clock(0, 0), clock(0, 0), 1)
133
+ assert_equal 7, w_week.week_total
134
+ w_week.workpattern(:all, clock(23, 59), clock(23, 59), 1)
135
+ assert_equal 14, w_week.week_total
136
+ w_week.workpattern(:all, clock(0, 0), clock(23, 59), 1)
137
+ assert_equal 10_080, w_week.week_total
138
+ w_week.workpattern(:weekend, clock(0, 0), clock(23, 59), 0)
139
+ assert_equal 7_200, w_week.week_total
140
+ end
141
+
142
+ def test_must_add_minutes_in_a_w_week_result_in_same_day
143
+ r_date, r_duration, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31),
144
+ 29)
145
+ assert_equal Time.gm(2000, 1, 3, 8, 0), r_date
146
+ refute m_flag
147
+ assert_equal 0, r_duration
148
+ end
149
+
150
+ def test_must_add_minutes_in_a_w_week_result_in_next_day
151
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 990)
152
+ assert_equal Time.gm(2000, 1, 4, 0, 1), r_date
153
+ refute m_flag
154
+ assert_equal 0, r_dur
155
+ end
156
+
157
+ def test_must_add_minutes_in_a_w_week_result_in_later_day
158
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 2430)
159
+ assert_equal Time.gm(2000, 1, 5, 0, 1), r_date
160
+ refute m_flag
161
+ assert_equal 0, r_dur
162
+ end
163
+
164
+ def test_must_add_minutes_in_a_w_week_result_in_start_next_day
165
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 989)
166
+ assert_equal Time.gm(2000, 1, 4, 0, 0), r_date
167
+ refute m_flag
168
+ assert_equal 0, r_dur
169
+ end
170
+
171
+ def test_must_add_0_minutes_in_a_w_week
172
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 0)
173
+ assert_equal Time.gm(2000, 1, 3, 7, 31), r_date
174
+ refute m_flag
175
+ assert_equal 0, r_dur
176
+ end
177
+
178
+ def test_must_add_too_many_minutes_in_a_w_week
179
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 9630)
180
+ assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
181
+ refute m_flag
182
+ assert_equal 1, r_dur
163
183
  end
164
184
 
165
185
  def test_must_add_minutes_in_a_resting_week
166
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,3,7,31),29)
167
- assert_equal DateTime.new(2000,1,10,0,0), result_date
168
- refute midnight_flag
169
- assert_equal 29, result_duration
186
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 7, 31), 29)
187
+ assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
188
+ refute m_flag
189
+ assert_equal 29, r_dur
170
190
  end
171
191
 
172
192
  def test_must_add_minutes_from_start_of_resting_week
173
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,3,0,0),990)
174
- assert_equal DateTime.new(2000,1,10,0,0), result_date
175
- refute midnight_flag
176
- assert_equal 990, result_duration
193
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 0, 0), 990)
194
+ assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
195
+ refute m_flag
196
+ assert_equal 990, r_dur
177
197
  end
178
198
 
179
199
  def test_must_add_minutes_to_last_minute_of_a_resting_week
180
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,9,23,59),2430)
181
- assert_equal DateTime.new(2000,1,10,0,0), result_date
182
- refute midnight_flag
183
- assert_equal 2430, result_duration
200
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 9, 23, 59), 2430)
201
+ assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
202
+ refute m_flag
203
+ assert_equal 2_430, r_dur
184
204
  end
185
205
 
186
206
  def test_must_add_zero_minutes_in_a_resting_week
187
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,3,7,31),0)
188
- assert_equal DateTime.new(2000,1,3,7,31), result_date
189
- refute midnight_flag
190
- assert_equal 0, result_duration
207
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 7, 31), 0)
208
+ assert_equal Time.gm(2000, 1, 3, 7, 31), r_date
209
+ refute m_flag
210
+ assert_equal 0, r_dur
191
211
  end
192
212
 
193
213
  def test_must_add_minutes_from_working_in_a_pattern_week_result_in_same_day
194
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,10,11),110)
195
- assert_equal DateTime.new(2000,1,3,12,1), result_date
196
- refute midnight_flag
197
- assert_equal 0, result_duration
214
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 110)
215
+ assert_equal Time.gm(2000, 1, 3, 12, 1), r_date
216
+ refute m_flag
217
+ assert_equal 0, r_dur
198
218
  end
199
219
 
200
220
  def test_must_add_minutes_from_resting_in_a_pattern_week_result_in_same_day
201
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,12,45),126)
202
- assert_equal DateTime.new(2000,1,3,15,7), result_date
203
- refute midnight_flag
204
- assert_equal 0, result_duration
221
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 126)
222
+ assert_equal Time.gm(2000, 1, 3, 15, 7), r_date
223
+ refute m_flag
224
+ assert_equal 0, r_dur
205
225
  end
206
226
 
207
227
  def test_must_add_minutes_from_working_in_a_pattern_week_result_in_next_day
208
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,10,11),379)
209
- assert_equal DateTime.new(2000,1,4,9,1), result_date
210
- refute midnight_flag
211
- assert_equal 0, result_duration
228
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 379)
229
+ assert_equal Time.gm(2000, 1, 4, 9, 1), r_date
230
+ refute m_flag
231
+ assert_equal 0, r_dur
212
232
  end
213
233
 
214
234
  def test_must_add_minutes_from_resting_in_a_pattern_week_result_in_next_day
215
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,12,45),240)
216
- assert_equal DateTime.new(2000,1,4,9,1), result_date
217
- refute midnight_flag
218
- assert_equal 0, result_duration
235
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 240)
236
+ assert_equal Time.gm(2000, 1, 4, 9, 1), r_date
237
+ refute m_flag
238
+ assert_equal 0, r_dur
219
239
  end
220
240
 
221
241
  def test_must_add_minutes_from_working_in_a_pattern_week_result_in_later_day
222
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,10,11),828)
223
- assert_equal DateTime.new(2000,1,5,9,1), result_date
224
- refute midnight_flag
225
- assert_equal 0, result_duration
242
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 828)
243
+ assert_equal Time.gm(2000, 1, 5, 9, 1), r_date
244
+ refute m_flag
245
+ assert_equal 0, r_dur
226
246
  end
227
247
 
228
- def test_must_add_minutes_from_resting_in_a_working_week_result_in_later_day
229
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,12,45),689)
230
- assert_equal DateTime.new(2000,1,5,9,1), result_date
231
- refute midnight_flag
232
- assert_equal 0, result_duration
248
+ def test_must_add_minutes_from_resting_in_a_w_week_result_in_later_day
249
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 689)
250
+ assert_equal Time.gm(2000, 1, 5, 9, 1), r_date
251
+ refute m_flag
252
+ assert_equal 0, r_dur
233
253
  end
234
254
 
235
255
  def test_must_add_0_minutes_from_working_in_a_resting_week
236
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,10,11),0)
237
- assert_equal DateTime.new(2000,1,3,10,11), result_date
238
- refute midnight_flag
239
- assert_equal 0, result_duration
256
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 0)
257
+ assert_equal Time.gm(2000, 1, 3, 10, 11), r_date
258
+ refute m_flag
259
+ assert_equal 0, r_dur
240
260
  end
241
261
 
242
262
  def test_must_add_0_minutes_from_resting_in_a_resting_week
243
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,12,45),0)
244
- assert_equal DateTime.new(2000,1,3,12,45), result_date
245
- refute midnight_flag
246
- assert_equal 0, result_duration
263
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 0)
264
+ assert_equal Time.gm(2000, 1, 3, 12, 45), r_date
265
+ refute m_flag
266
+ assert_equal 0, r_dur
247
267
  end
248
268
 
249
269
  def test_must_add_too_many_minutes_in_a_pattern__week
250
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,3,10,11),2175)
251
- assert_equal DateTime.new(2000,1,10,0,0), result_date
252
- refute midnight_flag
253
- assert_equal 1, result_duration
270
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 2175)
271
+ assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
272
+ refute m_flag
273
+ assert_equal 1, r_dur
254
274
  end
255
275
 
256
- def test_must_subtract_minutes_in_a_working_week_result_in_same_day
257
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,8,7,31),-29)
258
- assert_equal DateTime.new(2000,1,8,7,2), result_date
259
- refute midnight_flag
260
- assert_equal 0, result_duration
276
+ def test_must_subtract_minutes_in_a_w_week_result_in_same_day
277
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -29)
278
+ assert_equal Time.gm(2000, 1, 8, 7, 2), r_date
279
+ refute m_flag
280
+ assert_equal 0, r_dur
261
281
  end
262
282
 
263
- def test_must_subtract_minutes_in_a_working_week_result_in_previous_day
264
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,8,7,31),-452)
265
- assert_equal DateTime.new(2000,1,7,23,59), result_date
266
- refute midnight_flag
267
- assert_equal 0, result_duration
283
+ def test_must_subtract_minutes_in_a_w_week_result_in_previous_day
284
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -452)
285
+ assert_equal Time.gm(2000, 1, 7, 23, 59), r_date
286
+ refute m_flag
287
+ assert_equal 0, r_dur
268
288
  end
269
289
 
270
- def test_must_subtract_minutes_in_a_working_week_result_in_earlier_day
271
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,8,7,31),-1892)
272
- assert_equal DateTime.new(2000,1,6,23,59), result_date
273
- refute midnight_flag
274
- assert_equal 0, result_duration
290
+ def test_must_subtract_minutes_in_a_w_week_result_in_earlier_day
291
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -1892)
292
+ assert_equal Time.gm(2000, 1, 6, 23, 59), r_date
293
+ refute m_flag
294
+ assert_equal 0, r_dur
275
295
  end
276
296
 
277
- def test_must_subtract_minutes_in_a_working_week_result_at_start_of_day
278
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,8,7,31),-451)
279
- assert_equal DateTime.new(2000,1,8,0,0), result_date
280
- refute midnight_flag
281
- assert_equal 0, result_duration
297
+ def test_must_subtract_minutes_in_a_w_week_result_at_start_of_day
298
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -451)
299
+ assert_equal Time.gm(2000, 1, 8, 0, 0), r_date
300
+ refute m_flag
301
+ assert_equal 0, r_dur
282
302
  end
283
303
 
284
- def test_must_subtract_minutes_in_a_working_week_result_at_start_of_previous_day
285
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,8,7,31),-1891)
286
- assert_equal DateTime.new(2000,1,7,0,0), result_date
287
- refute midnight_flag
288
- assert_equal 0, result_duration
304
+ def test_must_subtract_minutes_in_a_w_week_result_at_start_of_previous_day
305
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -1891)
306
+ assert_equal Time.gm(2000, 1, 7, 0, 0), r_date
307
+ refute m_flag
308
+ assert_equal 0, r_dur
289
309
  end
290
310
 
291
- def test_must_subtract_too_many_minutes_from_a_working_week
292
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,8,7,31),-7652)
293
- assert_equal DateTime.new(2000,1,2,0,0), result_date
294
- assert midnight_flag
295
- assert_equal -1, result_duration
311
+ def test_must_subtract_too_many_minutes_from_a_w_week
312
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -7652)
313
+ assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
314
+ assert m_flag
315
+ assert_equal -1, r_dur
296
316
  end
297
317
 
298
- def test_must_subtract_1_minute_from_start_of_next_day_after_working_week
299
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,9,0,0),-1,true)
300
- assert_equal DateTime.new(2000,1,9,23,59), result_date
301
- refute midnight_flag
302
- assert_equal 0, result_duration
318
+ def test_must_subtract_1_minute_from_start_of_next_day_after_w_week
319
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 9, 0, 0), -1, true)
320
+ assert_equal Time.gm(2000, 1, 9, 23, 59), r_date
321
+ refute m_flag
322
+ assert_equal 0, r_dur
303
323
  end
304
324
 
305
- def test_must_subtract_2_minutes_from_start_of_next_day_after_working_week
306
- result_date, result_duration, midnight_flag = @working_week.calc(DateTime.new(2000,1,9,0,0),-2,true)
307
- assert_equal DateTime.new(2000,1,9,23,58), result_date
308
- refute midnight_flag
309
- assert_equal 0, result_duration
325
+ def test_must_subtract_2_minutes_from_start_of_next_day_after_w_week
326
+ r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 9, 0, 0), -2, true)
327
+ assert_equal Time.gm(2000, 1, 9, 23, 58), r_date
328
+ refute m_flag
329
+ assert_equal 0, r_dur
310
330
  end
311
331
 
312
332
  def test_must_subtract_minutes_from_last_day_in_a_resting_week
313
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,10,7,31),-29)
314
- assert_equal DateTime.new(2000,1,2,0,0), result_date
315
- assert midnight_flag
316
- assert_equal -29, result_duration
333
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 10, 7, 31), -29)
334
+ assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
335
+ assert m_flag
336
+ assert_equal -29, r_dur
317
337
  end
318
338
 
319
339
  def test_must_subtract_minutes_from_middle_day_in_a_resting_week
320
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,8,7,31),-452)
321
- assert_equal DateTime.new(2000,1,2,0,0), result_date
322
- assert midnight_flag
323
- assert_equal -452, result_duration
340
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 8, 7, 31), -452)
341
+ assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
342
+ assert m_flag
343
+ assert_equal -452, r_dur
324
344
  end
325
345
 
326
346
  def test_must_subtract_minutes_from_start_of_resting_week
327
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,3,0,0),-1892)
328
- assert_equal DateTime.new(2000,1,2,0,0), result_date
329
- assert midnight_flag
330
- assert_equal -1892, result_duration
347
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 0, 0), -1892)
348
+ assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
349
+ assert m_flag
350
+ assert_equal -1_892, r_dur
331
351
  end
332
352
 
333
353
  def test_must_subtract_minutes_from_start_of_next_day_after_resting_week
334
- result_date, result_duration, midnight_flag = @resting_week.calc(DateTime.new(2000,1,9,0,0),-1,true)
335
- assert_equal DateTime.new(2000,1,2,0,0), result_date
336
- assert midnight_flag
337
- assert_equal -1, result_duration
354
+ r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 9, 0, 0), -1, true)
355
+ assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
356
+ assert m_flag
357
+ assert_equal -1, r_dur
338
358
  end
339
-
359
+
340
360
  def test_must_subtract_minutes_from_resting_day_in_a_pattern_week
341
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,8,13,29),-29)
342
- assert_equal DateTime.new(2000,1,7,16,31), result_date
343
- refute midnight_flag
344
- assert_equal 0, result_duration
361
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 8, 13, 29), -29)
362
+ assert_equal Time.gm(2000, 1, 7, 16, 31), r_date
363
+ refute m_flag
364
+ assert_equal 0, r_dur
345
365
  end
346
366
 
347
367
  def test_must_subtract_minutes_from_working_day_in_a_pattern_week
348
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,7,13,29),-29)
349
- assert_equal DateTime.new(2000,1,7,12,29), result_date
350
- refute midnight_flag
351
- assert_equal 0, result_duration
368
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -29)
369
+ assert_equal Time.gm(2000, 1, 7, 12, 29), r_date
370
+ refute m_flag
371
+ assert_equal 0, r_dur
352
372
  end
353
373
 
354
374
  def test_must_subtract_minutes_in_a_pattern_week_result_in_previous_day
355
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,7,9,1),-2)
356
- assert_equal DateTime.new(2000,1,6,16,59), result_date
357
- refute midnight_flag
358
- assert_equal 0, result_duration
375
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 9, 1), -2)
376
+ assert_equal Time.gm(2000, 1, 6, 16, 59), r_date
377
+ refute m_flag
378
+ assert_equal 0, r_dur
359
379
  end
360
380
 
361
381
  def test_must_subtract_minutes_in_a_pattern_week_result_in_earlier_day
362
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,7,13,29),-240)
363
- assert_equal DateTime.new(2000,1,6,16,58), result_date
364
- refute midnight_flag
365
- assert_equal 0, result_duration
382
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -240)
383
+ assert_equal Time.gm(2000, 1, 6, 16, 58), r_date
384
+ refute m_flag
385
+ assert_equal 0, r_dur
366
386
  end
367
387
 
368
388
  def test_must_subtract_minutes_in_a_pattern_week_result_at_start_of_day
369
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,7,13,29),-238)
370
- assert_equal DateTime.new(2000,1,7,9,0), result_date
371
- refute midnight_flag
372
- assert_equal 0, result_duration
389
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -238)
390
+ assert_equal Time.gm(2000, 1, 7, 9, 0), r_date
391
+ refute m_flag
392
+ assert_equal 0, r_dur
373
393
  end
374
394
 
375
- def test_must_subtract_minutes_in_a_pattern_week_result_at_start_of_previous_day
376
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,7,13,29),-687)
377
- assert_equal DateTime.new(2000,1,6,9,0), result_date
378
- refute midnight_flag
379
- assert_equal 0, result_duration
395
+ def test_must_subtract_minutes_in_a_pattern_week_result_at_start_of_prev_day
396
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -687)
397
+ assert_equal Time.gm(2000, 1, 6, 9, 0), r_date
398
+ refute m_flag
399
+ assert_equal 0, r_dur
380
400
  end
381
401
 
382
402
  def test_must_subtract_too_many_minutes_from_a_pattern_week
383
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,7,9,0),-1797)
384
- assert_equal DateTime.new(2000,1,2,0,0), result_date
385
- assert midnight_flag
386
- assert_equal -1, result_duration
403
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 9, 0), -1797)
404
+ assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
405
+ assert m_flag
406
+ assert_equal -1, r_dur
387
407
  end
388
408
 
389
409
  def test_must_subtract_1_minute_from_start_of_next_day_after_pattern_week
390
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,9,0,0),-1,true)
391
- assert_equal DateTime.new(2000,1,7,16,59), result_date
392
- refute midnight_flag
393
- assert_equal 0, result_duration
410
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 9, 0, 0), -1, true)
411
+ assert_equal Time.gm(2000, 1, 7, 16, 59), r_date
412
+ refute m_flag
413
+ assert_equal 0, r_dur
394
414
  end
395
415
 
396
416
  def test_must_subtract_2_minutes_from_start_of_next_day_after_pattern_week
397
- result_date, result_duration, midnight_flag = @pattern_week.calc(DateTime.new(2000,1,9,0,0),-2,true)
398
- assert_equal DateTime.new(2000,1,7,16,58), result_date
399
- refute midnight_flag
400
- assert_equal 0, result_duration
417
+ r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 9, 0, 0), -2, true)
418
+ assert_equal Time.gm(2000, 1, 7, 16, 58), r_date
419
+ refute m_flag
420
+ assert_equal 0, r_dur
401
421
  end
402
422
 
403
- ######################################################
404
- # start=DateTime.new(2000,1,3)
405
- # finish=DateTime.new(2000,1,9)
406
- #
407
- # @pattern_week=Workpattern::Week.new(start,finish,1)
408
- # @pattern_week.workpattern(:weekend,Workpattern.clock(0,0),Workpattern.clock(23,59),0)
409
- # @pattern_week.workpattern(:weekday,Workpattern.clock(0,0),Workpattern.clock(8,59),0)
410
- # @pattern_week.workpattern(:weekday,Workpattern.clock(12,30),Workpattern.clock(13,0),0)
411
- # @pattern_week.workpattern(:weekday,Workpattern.clock(17,0),Workpattern.clock(23,59),0)
412
-
413
- ### @pattern_week centric
414
-
415
423
  def must_diff_day_week_day_in_patterned_week
416
- start=DateTime.new(2013,9,23,0,0)
417
- finish=DateTime.new(2013,10,20,23,59)
418
- working_week=week(start,finish,1)
419
- working_week.workpattern :all, Workpattern.clock(0,0),Workpattern.clock(8,59),0
420
- working_week.workpattern :all, Workpattern.clock(12,0),Workpattern.clock(12,59),0
421
- working_week.workpattern :all, Workpattern.clock(18,0),Workpattern.clock(23,59),0
422
-
423
- duration, start =working_week.diff(DateTime.civil(2013,10,3,16,0),DateTime.civil(2013,10,15,12,30))
424
-
425
- assert_equal 5640, duration
426
- assert_equal DateTime.civil(2013,10,15,12,30), start
427
-
428
- end
429
- def test_must_calculate_difference_between_dates_in_working_week
430
- late_date=DateTime.new(2000,1,6,9,32)
431
- early_date=DateTime.new(2000,1,6,8,20)
432
- result_dur, result_date = @working_week.diff(early_date,late_date)
424
+ start = Time.gm(2013, 9, 23, 0, 0)
425
+ finish = Time.gm(2013, 10, 20, 23, 59)
426
+ w_week = week(start, finish, 1)
427
+ w_week.workpattern :all, Workpattern.clock(0, 0),
428
+ Workpattern.clock(8, 59), 0
429
+ w_week.workpattern :all, Workpattern.clock(12, 0),
430
+ Workpattern.clock(12, 59), 0
431
+ w_week.workpattern :all, Workpattern.clock(18, 0),
432
+ Workpattern.clock(23, 59), 0
433
+ s_date = Time.gm(2013, 10, 3, 16, 0)
434
+ f_date = Time.gm(2013, 10, 15, 12, 30)
435
+ duration, start = w_week.diff(s_date, f_date)
436
+
437
+ assert_equal 5_640, duration
438
+ assert_equal Time.gm(2013, 10, 15, 12, 30), start
439
+ end
440
+
441
+ def test_must_calculate_difference_between_dates_in_w_week
442
+ late_date = Time.gm(2000, 1, 6, 9, 32)
443
+ early_date = Time.gm(2000, 1, 6, 8, 20)
444
+ result_dur, r_date = @w_week.diff(early_date, late_date)
433
445
  assert_equal 72, result_dur
434
- assert_equal late_date, result_date
446
+ assert_equal late_date, r_date
435
447
  end
436
448
 
437
449
  def test_must_calculate_difference_between_dates_in_resting_week
438
- late_date=DateTime.new(2000,1,6,9,32)
439
- early_date=DateTime.new(2000,1,6,8,20)
440
- result_dur, result_date = @resting_week.diff(early_date,late_date)
450
+ late_date = Time.gm(2000, 1, 6, 9, 32)
451
+ early_date = Time.gm(2000, 1, 6, 8, 20)
452
+ result_dur, r_date = @r_week.diff(early_date, late_date)
441
453
  assert_equal 0, result_dur
442
- assert_equal late_date, result_date
454
+ assert_equal late_date, r_date
443
455
  end
444
456
 
445
457
  def test_must_calculate_difference_between_dates_in_pattern_week
446
- late_date=DateTime.new(2000,1,6,13,1)
447
- early_date=DateTime.new(2000,1,6,12,29)
448
- result_dur, result_date = @pattern_week.diff(early_date,late_date)
458
+ late_date = Time.gm(2000, 1, 6, 13, 1)
459
+ early_date = Time.gm(2000, 1, 6, 12, 29)
460
+ result_dur, r_date = @p_week.diff(early_date, late_date)
449
461
  assert_equal 1, result_dur
450
- assert_equal late_date, result_date
462
+ assert_equal late_date, r_date
451
463
  end
452
464
 
453
465
  def test_must_diff_from_last_day_of_patterned_week
454
- #issue 15
455
- start=DateTime.new(2013,9,23,0,0)
456
- finish=DateTime.new(2013,9,26,23,59)
457
- working_week=week(start,finish,1)
458
- working_week.workpattern :all, Workpattern.clock(0,0),Workpattern.clock(8,59),0
459
- working_week.workpattern :all, Workpattern.clock(12,0),Workpattern.clock(12,59),0
460
- working_week.workpattern :all, Workpattern.clock(18,0),Workpattern.clock(23,59),0
461
-
462
- duration, start =working_week.diff(DateTime.civil(2013,9,26,17,0),DateTime.civil(2013,9,27,10,0))
466
+ # #issue 15
467
+ start = Time.gm(2013, 9, 23, 0, 0)
468
+ finish = Time.gm(2013, 9, 26, 23, 59)
469
+ w_week = week(start, finish, 1)
470
+ w_week.workpattern :all, Workpattern.clock(0, 0),
471
+ Workpattern.clock(8, 59), 0
472
+ w_week.workpattern :all, Workpattern.clock(12, 0),
473
+ Workpattern.clock(12, 59), 0
474
+ w_week.workpattern :all, Workpattern.clock(18, 0),
475
+ Workpattern.clock(23, 59), 0
476
+
477
+ s_date = Time.gm(2013, 9, 26, 17, 0)
478
+ f_date = Time.gm(2013, 9, 27, 10, 0)
479
+ duration, start = w_week.diff(s_date, f_date)
463
480
 
464
481
  assert_equal 60, duration
465
- assert_equal DateTime.civil(2013,9,27,0,0), start
482
+ assert_equal Time.gm(2013, 9, 27, 0, 0), start
466
483
  end
467
484
 
468
485
  def test_must_diff_long_distances_beyond_end_of_patterned_week
469
- start=DateTime.new(2013,9,23,0,0)
470
- finish=DateTime.new(2013,10,20,23,59)
471
- working_week=week(start,finish,1)
472
- working_week.workpattern :all, Workpattern.clock(0,0),Workpattern.clock(8,59),0
473
- working_week.workpattern :all, Workpattern.clock(12,0),Workpattern.clock(12,59),0
474
- working_week.workpattern :all, Workpattern.clock(18,0),Workpattern.clock(23,59),0
475
-
476
- duration, start =working_week.diff(DateTime.civil(2013,9,26,17,0),DateTime.civil(2018,9,27,10,0))
486
+ start = Time.gm(2013, 9, 23, 0, 0)
487
+ finish = Time.gm(2013, 10, 20, 23, 59)
488
+ w_week = week(start, finish, 1)
489
+ w_week.workpattern :all, Workpattern.clock(0, 0),
490
+ Workpattern.clock(8, 59), 0
491
+ w_week.workpattern :all, Workpattern.clock(12, 0),
492
+ Workpattern.clock(12, 59), 0
493
+ w_week.workpattern :all, Workpattern.clock(18, 0),
494
+ Workpattern.clock(23, 59), 0
477
495
 
478
- assert_equal 11580, duration
479
- assert_equal DateTime.civil(2013,10,21,0,0), start
496
+ s_date = Time.gm(2013, 9, 26, 17, 0)
497
+ f_date = Time.gm(2018, 9, 27, 10, 0)
498
+ duration, start = w_week.diff(s_date, f_date)
480
499
 
500
+ assert_equal 11_580, duration
501
+ assert_equal Time.gm(2013, 10, 21, 0, 0), start
481
502
  end
482
503
 
483
504
  def test_must_diff_long_distances_within_patterned_week
484
- start=DateTime.new(2013,9,23,0,0)
485
- finish=DateTime.new(2013,10,20,23,59)
486
- working_week=week(start,finish,1)
487
- working_week.workpattern :all, Workpattern.clock(0,0),Workpattern.clock(8,59),0
488
- working_week.workpattern :all, Workpattern.clock(12,0),Workpattern.clock(12,59),0
489
- working_week.workpattern :all, Workpattern.clock(18,0),Workpattern.clock(23,59),0
505
+ start = Time.gm(2013, 9, 23, 0, 0)
506
+ finish = Time.gm(2013, 10, 20, 23, 59)
507
+ w_week = week(start, finish, 1)
508
+ w_week.workpattern :all, Workpattern.clock(0, 0),
509
+ Workpattern.clock(8, 59), 0
510
+ w_week.workpattern :all, Workpattern.clock(12, 0),
511
+ Workpattern.clock(12, 59), 0
512
+ w_week.workpattern :all, Workpattern.clock(18, 0),
513
+ Workpattern.clock(23, 59), 0
490
514
 
491
- duration, start =working_week.diff(DateTime.civil(2013,9,26,17,0),DateTime.civil(2013,10,15,10,0))
492
-
493
- assert_equal 8760, duration
494
- assert_equal DateTime.civil(2013,10,15,10,0), start
515
+ s_date = Time.gm(2013, 9, 26, 17, 0)
516
+ f_date = Time.gm(2013, 10, 15, 10, 0)
517
+ duration, start = w_week.diff(s_date, f_date)
495
518
 
519
+ assert_equal 8_760, duration
520
+ assert_equal Time.gm(2013, 10, 15, 10, 0), start
496
521
  end
497
-
522
+
498
523
  private
499
-
500
- def week(start,finish,type)
501
- return Workpattern::Week.new(start,finish,type)
502
- end
503
-
504
- def clock(hour,min)
505
- return Workpattern.clock(hour,min)
506
- end
524
+
525
+ def week(start, finish, type)
526
+ Workpattern::Week.new(start, finish, type)
527
+ end
528
+
529
+ def clock(hour, min)
530
+ Workpattern.clock(hour, min)
531
+ end
507
532
  end