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/script/console
CHANGED
File without changes
|
data/script/destroy
CHANGED
File without changes
|
data/script/generate
CHANGED
File without changes
|
data/script/txt2html
CHANGED
File without changes
|
data/test/test_clock.rb
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class TestClock < MiniTest::
|
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,
|
12
|
-
assert_equal 0, clock.hour,
|
13
|
-
assert_equal 0, clock.min,
|
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.
|
16
|
-
assert_equal 0, time.hour,
|
17
|
-
assert_equal 0, time.min,
|
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,
|
24
|
-
assert_equal 4, clock.hour,
|
25
|
-
assert_equal 20, clock.min,
|
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.
|
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
|
data/test/test_helper.rb
CHANGED
File without changes
|
data/test/test_week.rb
CHANGED
@@ -1,507 +1,532 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
-
class TestWeek < MiniTest::
|
4
|
-
|
3
|
+
class TestWeek < MiniTest::Test #:nodoc:
|
4
|
+
include Workpattern::Base
|
5
5
|
def setup
|
6
|
-
start=
|
7
|
-
finish=
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
@
|
12
|
-
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
assert_equal
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
start
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
assert_equal
|
55
|
-
|
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=
|
60
|
-
finish=
|
61
|
-
resting_week=week(start,finish,0)
|
62
|
-
assert_equal
|
63
|
-
|
64
|
-
assert_equal
|
65
|
-
|
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=
|
70
|
-
finish=
|
71
|
-
week=week(start,finish,1)
|
72
|
-
new_week=week.duplicate
|
73
|
-
assert_equal
|
74
|
-
|
75
|
-
assert_equal
|
76
|
-
|
77
|
-
assert_equal
|
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=
|
82
|
-
finish=
|
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
|
88
|
-
pattern_week.workpattern(:weekend,Workpattern.clock(0,0),
|
89
|
-
|
90
|
-
pattern_week.
|
91
|
-
|
92
|
-
|
93
|
-
assert_equal
|
94
|
-
pattern_week.workpattern(:weekday,Workpattern.clock(
|
95
|
-
|
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=
|
100
|
-
finish=
|
101
|
-
|
102
|
-
assert_equal
|
103
|
-
|
104
|
-
assert_equal
|
105
|
-
|
106
|
-
assert_equal
|
107
|
-
|
108
|
-
assert_equal
|
109
|
-
|
110
|
-
assert_equal
|
111
|
-
|
112
|
-
assert_equal 0,
|
113
|
-
|
114
|
-
assert_equal 7,
|
115
|
-
|
116
|
-
assert_equal 14,
|
117
|
-
|
118
|
-
assert_equal
|
119
|
-
|
120
|
-
assert_equal
|
121
|
-
end
|
122
|
-
|
123
|
-
def
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
167
|
-
assert_equal
|
168
|
-
refute
|
169
|
-
assert_equal 29,
|
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
|
-
|
174
|
-
assert_equal
|
175
|
-
refute
|
176
|
-
assert_equal 990,
|
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
|
-
|
181
|
-
assert_equal
|
182
|
-
refute
|
183
|
-
assert_equal
|
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
|
-
|
188
|
-
assert_equal
|
189
|
-
refute
|
190
|
-
assert_equal 0,
|
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
|
-
|
195
|
-
assert_equal
|
196
|
-
refute
|
197
|
-
assert_equal 0,
|
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
|
-
|
202
|
-
assert_equal
|
203
|
-
refute
|
204
|
-
assert_equal 0,
|
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
|
-
|
209
|
-
assert_equal
|
210
|
-
refute
|
211
|
-
assert_equal 0,
|
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
|
-
|
216
|
-
assert_equal
|
217
|
-
refute
|
218
|
-
assert_equal 0,
|
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
|
-
|
223
|
-
assert_equal
|
224
|
-
refute
|
225
|
-
assert_equal 0,
|
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
|
229
|
-
|
230
|
-
assert_equal
|
231
|
-
refute
|
232
|
-
assert_equal 0,
|
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
|
-
|
237
|
-
assert_equal
|
238
|
-
refute
|
239
|
-
assert_equal 0,
|
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
|
-
|
244
|
-
assert_equal
|
245
|
-
refute
|
246
|
-
assert_equal 0,
|
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
|
-
|
251
|
-
assert_equal
|
252
|
-
refute
|
253
|
-
assert_equal 1,
|
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
|
257
|
-
|
258
|
-
assert_equal
|
259
|
-
refute
|
260
|
-
assert_equal 0,
|
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
|
264
|
-
|
265
|
-
assert_equal
|
266
|
-
refute
|
267
|
-
assert_equal 0,
|
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
|
271
|
-
|
272
|
-
assert_equal
|
273
|
-
refute
|
274
|
-
assert_equal 0,
|
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
|
278
|
-
|
279
|
-
assert_equal
|
280
|
-
refute
|
281
|
-
assert_equal 0,
|
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
|
285
|
-
|
286
|
-
assert_equal
|
287
|
-
refute
|
288
|
-
assert_equal 0,
|
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
|
292
|
-
|
293
|
-
assert_equal
|
294
|
-
assert
|
295
|
-
assert_equal -1,
|
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
|
299
|
-
|
300
|
-
assert_equal
|
301
|
-
refute
|
302
|
-
assert_equal 0,
|
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
|
306
|
-
|
307
|
-
assert_equal
|
308
|
-
refute
|
309
|
-
assert_equal 0,
|
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
|
-
|
314
|
-
assert_equal
|
315
|
-
assert
|
316
|
-
assert_equal -29,
|
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
|
-
|
321
|
-
assert_equal
|
322
|
-
assert
|
323
|
-
assert_equal -452,
|
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
|
-
|
328
|
-
assert_equal
|
329
|
-
assert
|
330
|
-
assert_equal -
|
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
|
-
|
335
|
-
assert_equal
|
336
|
-
assert
|
337
|
-
assert_equal -1,
|
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
|
-
|
342
|
-
assert_equal
|
343
|
-
refute
|
344
|
-
assert_equal 0,
|
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
|
-
|
349
|
-
assert_equal
|
350
|
-
refute
|
351
|
-
assert_equal 0,
|
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
|
-
|
356
|
-
assert_equal
|
357
|
-
refute
|
358
|
-
assert_equal 0,
|
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
|
-
|
363
|
-
assert_equal
|
364
|
-
refute
|
365
|
-
assert_equal 0,
|
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
|
-
|
370
|
-
assert_equal
|
371
|
-
refute
|
372
|
-
assert_equal 0,
|
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
|
376
|
-
|
377
|
-
assert_equal
|
378
|
-
refute
|
379
|
-
assert_equal 0,
|
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
|
-
|
384
|
-
assert_equal
|
385
|
-
assert
|
386
|
-
assert_equal -1,
|
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
|
-
|
391
|
-
assert_equal
|
392
|
-
refute
|
393
|
-
assert_equal 0,
|
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
|
-
|
398
|
-
assert_equal
|
399
|
-
refute
|
400
|
-
assert_equal 0,
|
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=
|
417
|
-
finish=
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
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,
|
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=
|
439
|
-
early_date=
|
440
|
-
result_dur,
|
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,
|
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=
|
447
|
-
early_date=
|
448
|
-
result_dur,
|
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,
|
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=
|
456
|
-
finish=
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
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
|
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=
|
470
|
-
finish=
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
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
|
-
|
479
|
-
|
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=
|
485
|
-
finish=
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
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
|
-
|
492
|
-
|
493
|
-
|
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
|
-
|
502
|
-
end
|
503
|
-
|
504
|
-
def clock(hour,min)
|
505
|
-
|
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
|